SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Aug 2006
    Posts
    375
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Missing one record in PHP loop

    Hopefully this is an easy one - I basically have a little loop to display records from a table of reviews on a page here :

    ereader reviews.

    However, the most recent record isn't displaying - so its like its missing the first record in the table, depending on the sort order.

    The query is just :

    PHP Code:
    mysql_select_db($database_connPixelar$connPixelar);
    $query_rsReviews "SELECT * FROM feedback WHERE Approved = 'Yes' ORDER BY feedbackID DESC";
    $rsReviews mysql_query($query_rsReviews$connPixelar) or die(mysql_error());
    $row_rsReviews mysql_fetch_assoc($rsReviews);
    $totalRows_rsReviews mysql_num_rows($rsReviews); 
    And the little loop looks like this :

    PHP Code:
           <?php 
         $groups 
    = array(); 
    while (
    $row mysql_fetch_assoc($rsReviews)) { 
        
    $groups[$row['Product']][] = $row

    foreach (
    $groups as $product_name => $rows) { 
        echo 
    "<tr><td class=\"product\">$product_name</td></tr>"
        foreach (
    $rows as $row) { 
            echo 
    "<tr><td class=\"review\">".$row['Review']."</td></tr>"
            echo 
    "<tr><td class=\"name\">".$row['CustomerName']."</td></tr>";
            echo 
    "<tr><td class=\"date\">".$row['Date']."</td></tr>";
        } 

    ?>
    If any one could shed any light on how to get it to display all the records that would be much appreciated.

    Thanks.

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    You are calling mysql_fetch_assoc($rsReviews); twice - once after the query and then in the loop.

    Delete the first one: $row_rsReviews = mysql_fetch_assoc($rsReviews); and it will be fine
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Addict
    Join Date
    Aug 2006
    Posts
    375
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you - that's all OK now.


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
  •