Page 1 of 1

mysql_fetch_assoc(): supplied argument is not a valid MySQ

Posted: Sat Nov 21, 2009 12:19 pm
by huntsvillepr
Please help. I am getting error message mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource

I have tested my connection and it works
I am getting result from echo $result

What I'm i doing wrong?

<?php
$con = mysql_connect("local","password","user");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

if (!mysql_select_db("dbname", $con)) {
exit('<p>Unable to connect');
}

$result = mysql_query ("SELECT id, title, description FROM dir_categories ");

if (!$result) {
echo 'no, no ';
}

echo $result;

$answer = mysql_query ($result);

while ($row = mysql_fetch_assoc ($answer)) {

echo '<title>'.htmlentities($row['title']).'</title>';
echo '<description>'.htmlentities($row['description']).'</description>';

}

mysql_close($con);
?>

Re: mysql_fetch_assoc(): supplied argument is not a valid MySQ

Posted: Sat Nov 21, 2009 1:18 pm
by BlaineSch
First of all use code tags!

Second, there are many things that could be wrong. If you table is empty you could be getting this.

Also try and use MySQLi because mysql is being depreciated.

Re: mysql_fetch_assoc(): supplied argument is not a valid MySQ

Posted: Sat Nov 21, 2009 3:11 pm
by requinix
Also,

Code: Select all

$result = mysql_query ("SELECT id, title, description FROM dir_categories ");
$answer = mysql_query ($result);
You run a query through mysql_query, then take the resource you get back and run it through mysql_query... $answer is false because $result is not a valid SQL query.

Re: mysql_fetch_assoc(): supplied argument is not a valid MySQ

Posted: Sun Nov 22, 2009 8:05 am
by huntsvillepr
thanks. the way i did the query was the problem