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> Link to comment https://forums.phpfreaks.com/topic/84180-using-a-table-to-display-results/ 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. Link to comment https://forums.phpfreaks.com/topic/84180-using-a-table-to-display-results/#findComment-428527 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. Link to comment https://forums.phpfreaks.com/topic/84180-using-a-table-to-display-results/#findComment-428531 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!!!!! Link to comment https://forums.phpfreaks.com/topic/84180-using-a-table-to-display-results/#findComment-428532 Share on other sites More sharing options...
hitman6003 Posted January 2, 2008 Share Posted January 2, 2008 http://us.php.net/operators.arithmetic Link to comment https://forums.phpfreaks.com/topic/84180-using-a-table-to-display-results/#findComment-428537 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?--> Link to comment https://forums.phpfreaks.com/topic/84180-using-a-table-to-display-results/#findComment-428554 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". Link to comment https://forums.phpfreaks.com/topic/84180-using-a-table-to-display-results/#findComment-428568 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. Link to comment https://forums.phpfreaks.com/topic/84180-using-a-table-to-display-results/#findComment-428571 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. Link to comment https://forums.phpfreaks.com/topic/84180-using-a-table-to-display-results/#findComment-428572 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.