2

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.

1

1 Answer 1

6

Replace this:

return("$sql");

With this:

return $sql;

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.