...

View Full Version : Always missing one record



Cacus
07-14-2006, 03:20 PM
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



<?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>
<?
}
?>

guelphdad
07-14-2006, 05:33 PM
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)

Kid Charming
07-14-2006, 06:13 PM
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.

Cacus
07-14-2006, 09:43 PM
Thank for the advice. Will give it a blast when I get back to my 'web' computer on Monday.

Cheers
Steve



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum