Database fetching gives warning

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
kkonline
Forum Contributor
Posts: 251
Joined: Thu Aug 16, 2007 12:54 am

Database fetching gives warning

Post by kkonline »

Code: Select all

$sql = "SELECT * FROM reflections WHERE `trusted` = 1 AND `catid` = 1 ORDER BY `id` ASC LIMIT $from, $max_results";

$result = mysql_query($sql) or die('select died: ' . mysql_error());
echo $sql;
echo $result;
while($row = mysql_fetch_array($sql))
{
... some data
}
To this it gives me $sql,$result followed by the warning as shown

SELECT * FROM reflections WHERE `trusted` = 1 AND `catid` = 1 ORDER BY `id` ASC LIMIT 8, 1

Resource id #6

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/mysite/public_html/addons/class.upload/pages.php on line 67
kkonline
Forum Contributor
Posts: 251
Joined: Thu Aug 16, 2007 12:54 am

Re: Database fetching gives warning

Post by kkonline »

Code: Select all

$sql = "SELECT * FROM reflections WHERE `trusted` = 1 AND `catid` = 1 ORDER BY `id` ASC LIMIT $from, $max_results";

$result = mysql_query($sql) or die('select died: ' . mysql_error());
echo $sql;
echo $result;
while($row = mysql_fetch_array($result)){
  echo "inside while loop";
}
Now the output is

SELECT * FROM reflections WHERE `trusted` = 1 AND `catid` = 1 ORDER BY `id` ASC LIMIT 8, 1
Resource id #6

No warnings but still it does not go into the while loop and print "inside while loop"... what could be the reason now? Any problem with the query
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

No records were found to match your query.
Post Reply