Jump to content
Larry Ullman's Book Forums

Function For Mysql


Recommended Posts

How can I change this into a function and include the file and call the function

I assumed it would be something similar to this but I guess I was wrong. I was hoping for some ideas thanks

 

funtion function_name($id){

$qv2='SELECT * FROM coaches WHERE sport_id = $id';

$rv2 = mysqli_query($dbc, $qv2);

 

if(mysqli_num_rows($rv2) > 0){

 

while($row = mysqli_fetch_array($rv2, MYSQLI_ASSOC)) {

$title = $row['title'];

 

if($title == 'Head Coach'){

echo'<p align="left" style="font-family: Verdana, Geneva, sans-serif; font-size: 10pt; text-align: center;"> ' ;

echo $row['coach_name'] . ' ' . $row['title'];

echo "\n<br />\n";

echo '<a href="mailto:' . $row['coach_email'] . ' ">' . $row['coach_email'] . '</a>';

echo "\n<br />\n";

echo "<br />\n";

//echo "\n</p>";

}

 

 

 

if ($title != 'Head Coach'){

echo $row['coach_name'] . ' - ' . $row['title'];

echo '<br />';

 

}

}

 

echo'</p>';

}else{echo 'nothing here to see';}

 

 

}

Link to comment
Share on other sites

Make sure you change the "funtion" keyword to "function". Other than that, just put the code in between some PHP tags, save the file and include it. For example:

 

File name: php_function.php

<?php

 function function_name($id) {

   // Code here

 }

?>

 

File in which you want to include the php_function.php file:

<?php

 include (path-to-file/php_function.php);

 // More code here. After the file is included, you can call the function.

?>

 

That's about it.

  • Upvote 1
Link to comment
Share on other sites

I had tried that and was getting an error. saying a system error had occured. because of the code i am using from the book. I am including a header file a config file and a mysql file where should this include be placed.

 

Also it should not matter it I have the code laid out like this should it

 

 

<?php

 

include('whateverFile/etc...');

include(path-to-file/php_function.php);

 

?>

 

Some Html

 

<?php some more code?>

 

more html

so on and so on

 

Hope this makes sense

Link to comment
Share on other sites

 Share

×
×
  • Create New...