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 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2006
    Posts
    96
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Always missing one record

    Hi can anyone tell me why the following code refuses to display the first record. (If I change the order from DESC to ASC I lose what was the last record but get the first).
    Cheers
    Steve

    Code:
    <?php 
    include('phpmysql/config.php');
    include('phpmysql/connect.php'); 
    $query = "SELECT * FROM bookshop ORDER BY title, author DESC";
    $result = mysql_query($query);
    $row = mysql_fetch_array($result);
    $totalrows = mysql_num_rows($result);
    if ($totalrows < '1') {
    ?>
    <p class="bodytext">No books available</p>
    <?
    }
    while ($row = mysql_fetch_array($result)) 
    {
    ?>
    <div class="bookshop_full_width_box">
    <div class="bookshop_cover_box"><img src="bookshop_images/<? echo ($row['coverimage']); ?>" alt="<? echo ($row['coverimage']); ?>"/></div>
    <div class="bookshop_centre_box">
    <div class="bookshop_title_author">
    <span class="bookshop_font_title"><? echo ($row['title']); ?><br></span>
    <span class="bookshop_font_author">by <? echo ($row['author']); ?><br></span>
    </div>
    <div class="bookshop_info">
    <span class="bookshop_font_synopsis"><? echo substr($row['synopsis'], 0, 865); ?></span>
    </div>
    <div id="bookshop_footers">
    <span class="bookshop_font_subheads">Pages : </span><span class="bookshop_font_synopsis"><? echo ($row['pages']); ?></span>
    <span class="whiteline">______</span>
    <span class="bookshop_font_subheads">Cover : </span><span class="bookshop_font_synopsis"><? echo ($row['cover']); ?></span>
    <span class="whiteline">______</span>
    <span class="bookshop_font_subheads">ISBN : </span><span class="bookshop_font_synopsis"><? echo ($row['isbn']); ?></span>
    </div>
    </div>
    <div class="bookshop_amazon_box"><? echo ($row['amazon_code']); ?></div>
    </div>
    <?
    }
    ?>

  • #2
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,634
    Thanks
    4
    Thanked 148 Times in 139 Posts
    That looks like it should work. Have you tried a basic test maybe with only one column and printed that out?

    are you successful in getting all the rows if you make your query directly in the mysql client or phpmyadmin? (i.e. without the php loop)

  • #3
    Regular Coder
    Join Date
    Jun 2005
    Posts
    804
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You're making one mysql_fetch_array() call before your while loop, so your while loop is starting on the second row of your result set. Remove that first fetch call, and you should be fine.

  • #4
    New Coder
    Join Date
    Jul 2006
    Posts
    96
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thank for the advice. Will give it a blast when I get back to my 'web' computer on Monday.

    Cheers
    Steve


  •  

    Posting Permissions

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