tags:

views:

92

answers:

1

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.

+6  A: 

Replace this:

return("$sql");

With this:

return $sql;

By surrounding $sql in quotes you are returning the string representation of the MySQL resource.

Paolo Bergantino