PDA

View Full Version : Horizontal Looping within another while loop


dprichard
05-06-2008, 01:07 PM
I know that I can do the following to loop something

$i=1;
while $i<5 {
}
$i++;

I have an array that I am looping through and I am trying to figure out how to loop horizontally and every 4 TD throw it down to the next row. So, loop for 4 horizontally, then break it with a </tr><tr> to start a new row. I am just having a little trouble figuring this out.

Any help would be greatly appreciated.

<table width="872">
<tr>
<?php while ($row_ticketdetails = mysql_fetch_array($ticketdetails)) { ?>
<td height="120" align="left" valign="top" class='criticaldetails'><div class="criticaltext">
Subject: <?php echo $row_ticketdetails['subject']; ?><br />
Name: <?php echo $row_ticketdetails['fullname']; ?><br />
Email: <?php echo $row_ticketdetails['email']; ?><br />
Phone: <?php echo $row_ticketdetails['phoneno']; ?></div>
</td>
<?php } ?>
</tr>
</table>

abduraooft
05-06-2008, 01:58 PM
See http://www.codingforums.com/showthread.php?t=129466

Stooshie
05-06-2008, 01:58 PM
<table width="872">
<tr>
<?php
counter = 1;
while ($row_ticketdetails = mysql_fetch_array($ticketdetails))
{
?>
<td height="120" align="left" valign="top" class='criticaldetails'><div class="criticaltext">
Subject: <?php echo $row_ticketdetails['subject']; ?><br />
Name: <?php echo $row_ticketdetails['fullname']; ?><br />
Email: <?php echo $row_ticketdetails['email']; ?><br />
Phone: <?php echo $row_ticketdetails['phoneno']; ?></div>
</td>
<?php
if($counter >= 4)
{
$counter = 0;
?>
</tr>
<tr>
<?
}
counter++;
}
?>
</tr>
</table>