I select results from database with limit 15 then i want to isernt them in three rows but i can't i am making this code: <table width="1%" align="center" cellpadding="0" cellspacing="0"> <tr> <?php $gamedt = mysql_query("SELECT * FROM `n-games` ORDER BY `count` LIMIT 15"); while($row = mysql_fetch_array($gamedt)){ $gameid = $row['gameid']; $title = $row['title']; $gameurl = $row['gameurl']; $gamepic = $row['gamepic']; $width = $row['width']; $height = $row['height']; $count = $row['count']; $category = $row['category']; ?> <td><center><? echo $title; ?></center> <a href="?page=play&file=<? echo $gameid; ?>"><img src="<? echo $gamepic; ?>" width="100" height="100" ></a></td> <? } ?> </tr> </table> PHP: in this example results are in one row and i want to insert them in three rows, in table like this <table> <tr> <td>5 results</td> </tr> <tr> <td>5 results</td> </tr> <tr> <td>5 results</td> </tr> </table> HTML: please help me
<table width="1%" align="center" cellpadding="0" cellspacing="0"> <tr> <?php $gamedt = mysql_query("SELECT * FROM `n-games` ORDER BY `count` LIMIT 15"); while($row = mysql_fetch_array($gamedt)){ $gameid = $row['gameid']; $title = $row['title']; $gameurl = $row['gameurl']; $gamepic = $row['gamepic']; $width = $row['width']; $height = $row['height']; $count = $row['count']; $category = $row['category']; ?> <td><center><? echo $title; ?></center> <a href="?page=play&file=<? echo $gameid; ?>"><img src="<? echo $gamepic; ?>" width="100" height="100" ></a></td> <? } ?> </tr> </table> PHP: you can try an x=0; above your while loop, and in your while loop x++; if ((x%5)==0) { echo //code to make a new row } PHP:
Try this. <table width="1%" align="center" cellpadding="0" cellspacing="0"> <tr> <?php $gamedt = mysql_query("SELECT * FROM `n-games` ORDER BY `count` LIMIT 15"); $rowcount = 0; while($row = mysql_fetch_array($gamedt)) { $gameid = $row['gameid']; $title = $row['title']; $gameurl = $row['gameurl']; $gamepic = $row['gamepic']; $width = $row['width']; $height = $row['height']; $count = $row['count']; $category = $row['category']; ?> <td><center><? echo $title; ?></center> <a href="?page=play&file=<? echo $gameid; ?>"><img src="<? echo $gamepic; ?>" width="100" height="100" ></a></td> <? if (++$rowcount % 3 == 0) { echo '</tr><tr>'; } } ?> </tr> </table> PHP: