The query works perfectly without a function. But when I try to put it in a function(), I get error (supplied argument is not a valid MySQL result resource) on 4 or 5 lines 🙂. Here is the query
<?php
include 'conetcion.php';
function select_sub_name(){
$Prof_Id = 8;
$query = "SELECT Sub_Name FROM subject WHERE Prof_Id = $Prof_Id";
//execute the SQL query and return records
$result=mysql_query($query);
$row = mysql_fetch_array ($result);
echo "<TABLE border=0>\n";
echo "<TR>\n";
foreach ($row as $heading=>$column) {
echo "<TD><b>";
echo "</b></TD>\n";
}
echo "</TR>\n";
mysql_data_seek ($result, 0);
while ($row = mysql_fetch_assoc ($result)) {
echo "<TR>\n";
foreach ($row as $column) {
//printing the results
echo "<TD>$column</TD>\n";
}
echo "</TR>\n";
}
echo "</TABLE>\n";
mysql_free_result($result);
}
select_sub_name();
?>
could it be because of the table or something else, if can pls write me the right way to do this.