yandoo Posted March 16, 2009 Share Posted March 16, 2009 Hi there, I was hoping for a little help please I have a query that pulls records from a mysql database and displays them in a page. My problem is that always the first record in the list is always empty, leaving an empty table row at the start of the records list. If you have quick scan of code and see whats up that would be nice. Thank You <table border="0" align="left" class="sortable"> <tr> <td width="167" align="left"><strong>Name</strong></td> <td width="145" align="left"><strong>Earliest Sow</strong></td> <td width="107" align="left"><strong>Germination </strong></td> <td width="61" align="left"><strong>Containers</strong></td> <td width="92" align="left"> </td> <td width="92" align="left"> </td> </tr> <tr> <td align="left"> </td> <td align="left"> </td> <td align="left"> </td> <td align="left"> </td> <td align="left"> </td> <td align="left"> </td> </tr> <?php do { ?> <tr> <td align="left"><a href="vegetables3.php?recordID=<?php echo $result['VegetableID']; ?>"> <input name="hiddenField" type="hidden" value="<?php echo $result['VegetableID']; ?>" /> </a><a href="vegetables3.php?recordID=<?php echo $result['VegetableID']; ?>"> <input name="hiddenField2" type="hidden" value="<?php echo $result['FamilyID']; ?>" /> </a><a href="vegetables3.php?recordID=<?php echo $result['VegetableID']; ?>"> <input name="hiddenField3" type="hidden" value="<?php echo $result['TypeID']; ?>" /> <input name="hiddenField4" type="hidden" value="<?php echo $result['EnviromentID']; ?>" /> <input name="hiddenField5" type="hidden" value="<?php echo $result['Description']; ?>" /> </a> <a href="vegetables4.php?recordID=<?php echo $result['VegetableID']; ?>"><?php echo $result['Name']; ?></a></td> <td align="left"><?php echo $result['Sow']; ?></td> <td align="left"><?php echo $result['Proptime']; ?> Days </td> <td align="left"><input disabled="disabled"<?php if (!(strcmp($result['Pots'],1))) {echo "checked=\"checked\"";} ?> name="pots" type="checkbox" id="pots" value="checkbox" /></td> <td align="left"><?php echo "<img src=".$result['image']." height =\"60\" width=\"80\">"; ?></td> <td align="left"><?php if ( $row_user['Access'] == "1" ) {?> <?php }?> <a href="vegetables3.php?recordID=<?php echo $result['VegetableID']; ?>">Edit</a></td> </tr><?php } while ($result = mysql_fetch_assoc($data)); {?> </table> <?php } } //This counts the number or results - and if there wasn't any it gives them a little message explaining that $anymatches=mysql_num_rows($data); if ($anymatches == 0) { echo "Sorry, but we can not finda an entry to match your query<br><br>"; } ?> Link to comment https://forums.phpfreaks.com/topic/149720-empty-table-rowrecord-appears-1st-in-list-of-records/ Share on other sites More sharing options...
PFMaBiSmAd Posted March 16, 2009 Share Posted March 16, 2009 do/while loops are almost never used because the first time through the loop, you would need to setup the data values. In your code, $result does not exists on the first pass through the loop because it is assigned inside of the while() statement at the end of the loop. You should use a normal while() loop, not a do/while. Link to comment https://forums.phpfreaks.com/topic/149720-empty-table-rowrecord-appears-1st-in-list-of-records/#findComment-786212 Share on other sites More sharing options...
yandoo Posted March 16, 2009 Author Share Posted March 16, 2009 Hi and thanks for reply When i remove the "do" and move the "while" loop it doesnt display any records and just the blank record/table row. Im probably being stupid, but what am i missing... Thanks Link to comment https://forums.phpfreaks.com/topic/149720-empty-table-rowrecord-appears-1st-in-list-of-records/#findComment-786233 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.