Share Prices - Actress - Hen Night - PSD to HTML - Free mobile phone's stuffs

PDA

View Full Version : insert results in rows


shotazi
Oct 28th 2007, 12:56 pm
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>
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>

please help me :(

Lordy
Oct 28th 2007, 1:56 pm
<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>
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
}

shotazi
Oct 29th 2007, 1:43 am
it does not work :(

what i can to do? :(

Lordy
Oct 29th 2007, 2:49 am
it seems like your code to display the table is outside of php

nico_swd
Oct 29th 2007, 3:42 am
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>

shotazi
Oct 29th 2007, 7:34 am
nico_swd
yaaa it is workiing thannk you veerry much.