...

View Full Version : Resolved Php while loop error



masterofollies
05-02-2009, 12:46 AM
Can someone see an error in this? I don't understand why I get the error.


$links = mysql_query("SELECT * FROM links WHERE id>'0'");

while ($linkrow = mysql_fetch_array($links))
{
echo "<a href=\"".$linkrow['url']."\">".$linkrow['linkname']."</a><br />";
}



Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/admin/public_html/index.php on line 192

hthought
05-02-2009, 01:38 AM
Seems ok, i'd suggest that you take a look at your naming, for instance is the table indeed named as links? I think that this could most probably be a typographical error, recheck your table and column names carefully please.

sea4me
05-02-2009, 01:54 AM
Think your id needs to be `


$links = mysql_query("SELECT * FROM links WHERE `id` > '0'");

while ($linkrow = mysql_fetch_array($links))
{
echo "<a href=\"".$linkrow['url']."\">".$linkrow['linkname']."</a><br />";
}

masterofollies
05-02-2009, 04:33 AM
I didn't setup the table yet, because I thought it should just be a blank space and not show any results?

Fou-Lu
05-02-2009, 05:18 AM
I didn't setup the table yet, because I thought it should just be a blank space and not show any results?

The table is required. The query is returning a false since it failed to retreive any results (since the table does not exist). It is not the same as retreiving 0 records, and the mysql_fetch_assoc is failing due to an invalid resultset pointer.

masterofollies
05-02-2009, 03:17 PM
Yeah got it working



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum