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);
?>
mysql_fetch_assoc(): supplied argument is not a valid MySQ
Moderator: General Moderators
-
huntsvillepr
- Forum Newbie
- Posts: 7
- Joined: Wed Nov 18, 2009 2:21 am
- BlaineSch
- Forum Commoner
- Posts: 28
- Joined: Sun Jun 07, 2009 4:28 pm
- Location: Trapped in my own little world.
Re: mysql_fetch_assoc(): supplied argument is not a valid MySQ
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.
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
Also,
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.
Code: Select all
$result = mysql_query ("SELECT id, title, description FROM dir_categories ");
$answer = mysql_query ($result);-
huntsvillepr
- Forum Newbie
- Posts: 7
- Joined: Wed Nov 18, 2009 2:21 am
Re: mysql_fetch_assoc(): supplied argument is not a valid MySQ
thanks. the way i did the query was the problem