the problem with the listing. nested loops?
I am here to open a new line after every 6 from the data that I want to draw the line data. When the 6-like following code prints the data 36 times. that this function is checking how many games. If I mention below, but as there are now 36 with 6 printing units. Each one of the prints 6 times.
for($i = 0; $i < $db->oyunSayisi(); $i++)
{
if ($i % 6 == 0)开发者_StackOverflow社区
{
echo "<tr>";
}
?>
<br/>
<?php
foreach($db->oyunCek() as $oyun)
{
?>
<td width="224" height="115"><a href="<?=$db->siteAdres()?>/oyun.php?id=<?=$oyun['o_id']?>" title="<?=$oyun['o_baslik']?> oyna"><img height="115;110" src="<?=$db->siteAdres()?>/resimler/<?=$oyun['o_resim']?>" title="<?=$oyun['o_baslik']?> oyna" alt="<?=$oyun['o_baslik']?> oyna" /></a></td>
<?php
}
if ($i % 6 == 0)
{
echo "</tr>";
}
}
I think I see what may be causing the problem.
For every sixth item returned from oyunSayisi()
, you want to create a table row that shows the data from oyunCek()
. The problem is that the first modulus just outputs <tr>
, then every line runs the foreach
loop. Finally, the second modulus outputs </tr>
. I think you want to combine everything into just one modulus, like this:
for($i = 0; $i < $db->oyunSayisi(); $i++)
{
if ($i % 6 == 0)
{
echo "<tr><br/>\n";
foreach($db->oyunCek() as $oyun)
{
?>
<td width="224" height="115"><a href="<?=$db->siteAdres()?>/oyun.php?id=<?=$oyun['o_id']?>" title="<?=$oyun['o_baslik']?> oyna"><img height="115;110" src="<?=$db->siteAdres()?>/resimler/<?=$oyun['o_resim']?>" title="<?=$oyun['o_baslik']?> oyna" alt="<?=$oyun['o_baslik']?> oyna" /></a></td>
<?php
}
echo "</tr>\n";
}
}
EDIT:
Upon further pondering, it did not make sense that you would want to only echo every sixth line of data... so it occurred to me that you are probably trying to create a new table row every sixth line, rather than skipping any of the inner foreach
loops. Here is the modified code to do that:
echo "<tr>\n";
for($i = 0; $i < $db->oyunSayisi(); $i++)
{
foreach($db->oyunCek() as $oyun)
{
?>
<td width="224" height="115"><a href="<?=$db->siteAdres()?>/oyun.php?id=<?=$oyun['o_id']?>" title="<?=$oyun['o_baslik']?> oyna"><img height="115;110" src="<?=$db->siteAdres()?>/resimler/<?=$oyun['o_resim']?>" title="<?=$oyun['o_baslik']?> oyna" alt="<?=$oyun['o_baslik']?> oyna" /></a></td>
<?php
}
if (($i + 1) % 6 == 0)
{
echo "</tr>\n<tr>\n";
}
}
精彩评论