* Thus wrote nabil ([EMAIL PROTECTED]):
> Hiya,
>
> How can i draw a new <tr> AFTER FIVE <td> in the following loop
>
> (i want to echo the records in 5 columns width tables whatever the number of
> records will be fetched)
>
> ..
> echo '<table>';
>
> while ($myrow = mysql_fetch_array($sql))
> {
> echo $myrow[0];
> }
> echo '</table>';
Use the modulus (%) operator.
$columns = 5; // Human readable number
$new_row = $columns - 1; // the magic number
$html_row = ''; // Column buffer
$i = 0; // Counter
echo '<table>';
while (...) {
$html_row .= "<td>{$myrow[0]}</td>";
// $i % $columns sequence will be:
// 0, 1, 2, 3, 4, 0, 1, 2, 3, 4 ...
if ( ($i % $columns) == $new_row ) {
echo "<tr>$html_row</tr>";
$html_row = '';
$i++;
}
}
// if we are on a sequence number other than zero
// html_row will contain some columns.
if(($i % $columns) != 0) {
echo "<tr>$html_row</tr>";
}
echo '</table>';
Curt
--
"I used to think I was indecisive, but now I'm not so sure."
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php