Reputation: 22527
I have a really simple function:
function experience_query($id) {
$sql = @mysql_query(
"
SELECT * FROM table WHERE id = $id
");
return("$sql");
}
When I call this function:
$q = categories_query("1001");
while( $list = mysql_fetch_assoc($q) )
{
extract($list);
echo $name;
}
I am getting an error" "mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource..."
Am I allowed to return mysql queries from a function?
Thank you for your help.
Upvotes: 2
Views: 1974
Reputation: 488414
Replace this:
return("$sql");
With this:
return $sql;
By surrounding $sql
in quotes you are returning the string representation of the MySQL resource.
Upvotes: 6