Based on the php manual you have an error with your query. My guess is $name is a string and not an $id number. echo out the value of $name to verify that when it is inserted into the query, that the query is valid.
function get_subjects($name){
$sql = "SELECT * FROM subjects WHERE id = {$name} LIMIT 1";
echo $sql; // comment out this line after you fix the mysql query issue
$query = mysql_query($sql);
if($results = mysql_fetch_array($query)){
return $results;
}else{
return NULL;
}
}
In addition to echoing out the query, when you are debugging you can use the ‘or die’ construction to get more info about the error if there is one:
function get_subjects($name) {
$sql = "SELECT * FROM subjects WHERE id = {$name} LIMIT 1";
echo $sql; // comment out this line after you fix the mysql query issue
$query = mysql_query($sql) or die(' mysql error ' . mysql_error());
if ($results = mysql_fetch_array($query)) {
return $results;
} else {
return NULL;
}
}
The problem in my view i m watching lynda.com php and mysql essential training and when kevin skougland do refactoring, everything get messed up. i think refactoring is a very advance level for me. still i m trying my way around it. just stuck on this step.
As you have not displayed a [FPHP]mysql_select_db[/FPHP] command in your paste, i’m assuming you dont have one. Specify one and you should clear that error
Maybe you could try to apply what is being explained to you? If you used the tips given in this thread to this new query (put the query string in a variable, echo out that variable, use the ‘or die’ construction) then you probably would have found that error yourself.
we are passing a argument and when we want to echo it to see what is query. what would the passed in argument will return coz we haven’t called that function