Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts

    Php while loop error

    Can someone see an error in this? I don't understand why I get the error.

    PHP Code:
    $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
    Last edited by masterofollies; 05-02-2009 at 03:17 PM.

  • #2
    New Coder
    Join Date
    May 2009
    Posts
    55
    Thanks
    1
    Thanked 4 Times in 4 Posts
    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.

  • #3
    Regular Coder sea4me's Avatar
    Join Date
    Jan 2009
    Location
    Damn, I don't know...
    Posts
    390
    Thanks
    11
    Thanked 28 Times in 27 Posts
    Think your id needs to be `

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

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

  • #4
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    I didn't setup the table yet, because I thought it should just be a blank space and not show any results?

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Quote Originally Posted by masterofollies View Post
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #6
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Yeah got it working


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •