Dragen Posted April 13, 2007 Share Posted April 13, 2007 I'm trying to write some script that will get info from my table and put it into an html table. <table border="0" cellpadding="0" cellspacing="0" align="center" width="100%"> <tr> <?php $result = mysql_query("SELECT * FROM booked"); $no = 0; for($no = 0; $no <= 5; $no++){ $row = mysql_fetch_array($result); echo "\t\t<td align=\"center\">"; echo $row['day'] . " / " . $row['month'] . " / " . $row['year']; echo "</td>\n"; if($no == 5){ echo "\t</tr>\n\t<tr>"; } } ?> </tr> </table> This is what I've got so far, but it's not working... What should happen is when it reaches 6 column across it starts on a new row. At the moment it's just putting the first six along the top and stopping.. I can't seem to get the code right to make it continue on another line... note: yes I do mean 6 colums although it says $no <= 5; This is because the first is counted as 0 Quote Link to comment Share on other sites More sharing options...
btherl Posted April 13, 2007 Share Posted April 13, 2007 When $no == 5, you also need to reset it back to 0. But the other thing you need to do is break the loop when there's no data left: if ($row === false) break; ... if ($no == 5) { echo "\t</tr>\n\t<tr>"; $no = 0; } Quote Link to comment Share on other sites More sharing options...
Dragen Posted April 13, 2007 Author Share Posted April 13, 2007 ah thanks.. I'd already tried resetting it to 0 again, but for some reason deleted that part when I pasted the code on here :-\ My problem was I hadn't put in a break. Thanks! Quote Link to comment 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.