SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    grasshoppa Snowbird122's Avatar
    Join Date
    Apr 2001
    Location
    Austin
    Posts
    353
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php loop through recordset

    I user the following to loop through a recordset, but it always skips the first record. What am I doing wrong?

    while ($query_data = mysql_fetch_array($result))
    http://www.echo-consulting.net - Sound Solutions for Online Inspriations.

  2. #2
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is nothing wrong with that, the problem is more likely to be with your query. Can you post it please

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  3. #3
    SitePoint Zealot
    Join Date
    Aug 2001
    Location
    North Carolina
    Posts
    153
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Odd, it looks exactly like the line I've been using:
    PHP Code:
    while($line mysql_fetch_array($result)) 
    I'll look through my tables and make sure I've not been missing something...
    Andrew Thompson
    VPHost.com, part of the Untapped Resources Network.

  4. #4
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is nothing wrong with that, I think the problem will be with the query stored in $result

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  5. #5
    grasshoppa Snowbird122's Avatar
    Join Date
    Apr 2001
    Location
    Austin
    Posts
    353
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is my query:
    $PictureQuery = "SELECT * FROM Products WHERE Product_ID like '%" . $search . "%' OR Title like '%" . $search . "%' OR Long_Description like '%" . $search . "%' OR Keywords like '%" . $search . "%' OR Artist like '%" . $search . "%' limit " . $LowerRecord . ", " . $UpperRecord;

    $result = mysql_query($PictureQuery, $link_id);
    while ($query_data = mysql_fetch_array($result))
    http://www.echo-consulting.net - Sound Solutions for Online Inspriations.

  6. #6
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does $LowerRecord start at 1 or 0. In order to get the first record make sure it starts at 0. Incidentally since your query is encapsulated in double quotes you can write it a little more cleanly.

    PHP Code:
    $PictureQuery "SELECT * FROM Products WHERE Product_ID like '%$search%' OR 
                    Title like '%
    $search%' OR Long_Description like '%$search%' OR 
                    Keywords like '%
    $search%' OR Artist like '%$search%' limit $LowerRecord$UpperRecord"
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  7. #7
    grasshoppa Snowbird122's Avatar
    Join Date
    Apr 2001
    Location
    Austin
    Posts
    353
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks everyone for your input to this most puzzling problem. I don't think the problem has anything to do with my lowerrecord base. I used the same piece of code everywhere, and it always skips the first record. Here is a much more simple example:

    $SearchQuery = "SELECT * from contacts";
    $rstResult = mysql_query($SearchQuery, $link_id);
    $query_data = mysql_fetch_array($rstResult);
    ShowRS($query_data, $rstResult);

    function ShowRS($query_data, $rstResult)
    {
    echo "<table border=1>";
    while ($query_data = mysql_fetch_array($rstResult)) //loops through every record
    {
    echo "<tr><td align=center><a href=contacts.php?action=edit&id=" . $query_data["contact_id"] . ">Edit</a></td><td>" . $query_data["last_name"] . "</td><td>" . $query_data["first_name"] . "</td><td>" . $query_data["address"] . "</td><td>" . $query_data["city"] . "</td><td>" . $query_data["state"] . "</td><td>" . $query_data["zip"] . "</td><td>" . $query_data["phone"] . "</td><td>" . $query_data["email"] . "</td><td>" . $query_data["birthdate"] . "</td><td>" . $query_data["family_member_status"] . "</td><td>" . $query_data["FUN"] . "</td><td>" . $query_data["gender"] . "</td><td>" . $query_data["membership_date"] . "</td><td>" . $query_data["bible_class"] . "</td><td>" . $query_data["marital_status"] . "</td><td>" . $query_data["comments"] . "</td><td align=center><a href=contacts.php?action=delete&id=" . $query_data["contact_id"] . ">X</a></td>";
    }
    }
    Last edited by Snowbird122; Aug 26, 2001 at 14:55.
    http://www.echo-consulting.net - Sound Solutions for Online Inspriations.

  8. #8
    grasshoppa Snowbird122's Avatar
    Join Date
    Apr 2001
    Location
    Austin
    Posts
    353
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am an asp programmer trying to do PHP. In asp, you cannot place variables inside double quotes, so I just do that to be consistent with both languages, even though it is much cleaner your way freddy.
    Last edited by Snowbird122; Aug 26, 2001 at 14:44.
    http://www.echo-consulting.net - Sound Solutions for Online Inspriations.

  9. #9
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your problem is you call

    $query_data = mysql_fetch_array($rstResult);

    right after the query, this makes it skip to the second record of the resultset. Take that line out. And just use the while($query_data = mysql_fetch_array($rstResult)) {
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  10. #10
    grasshoppa Snowbird122's Avatar
    Join Date
    Apr 2001
    Location
    Austin
    Posts
    353
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    freddy you da man. You were exactly right.
    Thanks for your help, I really appreciate it.
    http://www.echo-consulting.net - Sound Solutions for Online Inspriations.


Bookmarks

Posting Permissions

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