RynMan Posted October 7, 2010 Share Posted October 7, 2010 Hey guys I'm not amazing at PHP, but know just enough to be dangerous. Basically I'm trying to get these records from my database to display in rows of 4. For some reason every time, I'm missing a record (the first record returned in my query). It's probably something simple is my code. Would be grateful if anyone could lend a suggestion. <?php $a=0; $b=3; while ($ArrayData = mysql_fetch_array($QueryData)) { //if a=0, start new row if ($a==0) { echo '<tr>'; } //create cell //if thumbnail exists, use it, otherwise throw in the unavailable image if ($ArrayData["PhotoThumb"]!="") { $ImageToUse = $ArrayData["PhotoThumb"]; } else { $ImageToUse = "image_unavailable_thumb.jpg"; } echo ' <td width="33%" align="center" valign="top"><p><a href="item.php?ItemID='.$ArrayData["ItemID"].'"><img src="images/'.$ImageToUse.'" border="0" /></a></p> <p><a href="item.php?ItemID='.$ArrayData["ItemID"].'" class="cart_body_text">'.$ArrayData["ItemName"].'</a><br /> <span class="style1"> <strong>$'.sprintf("%01.2f", $ArrayData["UnitPrice"]).'</strong></span><br /> </p> </td>'; //increment by 1 $a++; //if a = 3 then close the row using </tr>, ready to start a new one if ($a==$b) { echo ' </tr>'; //reset counter, ready to start new row $a=0; } } if ($a > 0 ) { echo '</tr>'; } ?> Thanks guys! Quote Link to comment https://forums.phpfreaks.com/topic/215330-missing-one-record-from-my-display/ Share on other sites More sharing options...
trq Posted October 7, 2010 Share Posted October 7, 2010 You forgot to show us the piece of code that executes the query. Do you call mysql_fetch_array() anywhere else before the code you have posted? Quote Link to comment https://forums.phpfreaks.com/topic/215330-missing-one-record-from-my-display/#findComment-1119758 Share on other sites More sharing options...
RynMan Posted October 7, 2010 Author Share Posted October 7, 2010 Ah yep, sorry! $QueryData = mysql_query("SELECT * FROM `Items` WHERE ItemCategoryShort = '$ItemCategory' ORDER BY UnitPrice ASC", $connection); if (!$QueryData) { die("Database query failed" . mysql_error()) ; } $ArrayData = mysql_fetch_array($QueryData); Quote Link to comment https://forums.phpfreaks.com/topic/215330-missing-one-record-from-my-display/#findComment-1119759 Share on other sites More sharing options...
trq Posted October 7, 2010 Share Posted October 7, 2010 Remove the..... $ArrayData = mysql_fetch_array($QueryData); line. Quote Link to comment https://forums.phpfreaks.com/topic/215330-missing-one-record-from-my-display/#findComment-1119766 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.