ohdang888 Posted January 2, 2008 Share Posted January 2, 2008 heres the code i have right now, it works... but how do i say, "after 5 results are displayed, then echo "'</tr>'.'<tr>'"".....???????? <table> <tr> <?php mysql_connect("localhost", "----", "-----") or die(mysql_error()); mysql_select_db("games") or die(mysql_error()); $new_games = mysql_query("SELECT link, game_picture_url, type, counter FROM game ORDER BY counter LIMIT 10") or die(mysql_error()); while($row2 = mysql_fetch_assoc($new_games)){ echo '<td>'; echo'<center>'; echo '<font size=3>'; echo '<img src="gamepic/'; echo $row2['game_picture_url']; echo '" height="120" width="120"><br>'; echo $row2['link'].'<br>'; echo '<font size=2>'; echo '('; echo $row2['type']; echo ')'; echo '</td>'; } ?> </tr> Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted January 2, 2008 Share Posted January 2, 2008 I prefer the modulus method: $x = 0; echo '<tr>'; while($row2 = mysql_fetch_assoc($new_games)){ if ($x % 5 == 0) { echo '</tr><tr>'; } $x++; echo '<td>'; echo'<center>'; echo '<font size=3>'; echo '<img src="gamepic/'; echo $row2['game_picture_url']; echo '" height="120" width="120"><br>'; echo $row2['link'].'<br>'; echo '<font size=2>'; echo '('; echo $row2['type']; echo ')'; echo '</td>'; } However, there are, of course, many others. Quote Link to comment Share on other sites More sharing options...
AV1611 Posted January 2, 2008 Share Posted January 2, 2008 You got a page that I can read about the way you used % in that post? Thanks. Quote Link to comment Share on other sites More sharing options...
ohdang888 Posted January 2, 2008 Author Share Posted January 2, 2008 ya same here. ps.- thanks for the code!!!!! Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted January 2, 2008 Share Posted January 2, 2008 http://us.php.net/operators.arithmetic Quote Link to comment Share on other sites More sharing options...
ohdang888 Posted January 2, 2008 Author Share Posted January 2, 2008 would i still need to put </tr> after the whole php code?????????? example of what i',m talking about... <?php mysql_connect("localhost", ----", "---") or die(mysql_error()); mysql_select_db("games") or die(mysql_error()); $new_games = mysql_query("SELECT link, game_picture_url, type, date_added FROM game ORDER BY date_added LIMIT 10") or die(mysql_error()); $x = 0; echo '<tr>'; while($row2 = mysql_fetch_assoc($new_games)){ if ($x % 5 == 0) { echo '</tr><tr>'; } $x++; echo '<td>'; echo'<center>'; echo '<font size=3>'; echo '<img src="gamepic/'; echo $row2['game_picture_url']; echo '" height="120" width="120"><br>'; echo $row2['link'].'<br>'; echo '<font size=2>'; echo '('; echo $row2['type']; echo ')'; echo '</td>'; } ?> </tr> <!--DO I NEED THIS?--> Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted January 2, 2008 Share Posted January 2, 2008 yes, you would still need it...and something to fill out any remaining td's to make the rows even: $x = 0; echo '<tr>'; while($row2 = mysql_fetch_assoc($new_games)){ if ($x % 5 == 0) { echo '</tr><tr>'; } $x++; echo '<td>'; echo'<center>'; echo '<font size=3>'; echo '<img src="gamepic/'; echo $row2['game_picture_url']; echo '" height="120" width="120"><br>'; echo $row2['link'].'<br>'; echo '<font size=2>'; echo '('; echo $row2['type']; echo ')'; echo '</td>'; } while ($x < 5) { echo '<td> </td>'; $x++; } echo '</tr>'; The part to fill out the row should be necessary with any implementation to keep your html "proper". Quote Link to comment Share on other sites More sharing options...
ohdang888 Posted January 2, 2008 Author Share Posted January 2, 2008 well there are hundreds of rows from it to choose form, and i am limiting 10. so i won't have that problem. Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted January 2, 2008 Share Posted January 2, 2008 You may have to start $x at 1, rather than 0, or your first row could have 6 td's. 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.