You are here: Re: simple loop? help « PHP Programming Language « IT news, forums, messages
Re: simple loop? help

Posted by Mara Guida on 10/02/60 11:34

Bob Bedford wrote:
> I do probably need a good coffee, but I can't find out a simple way to do
> so.
>
> Let's say I want to create a table using a number I receive.
> For every number, I must have a table with maximum 5 columns.
>
> Example:
> 10 will gives 2 rows of 5 columns
> 12 will gives 2 rows of 5 columns and a row of 2 columns.
> ....
>
> The problem is that I've to keep the value of every cell like this for 12
> 1 2 3 4 5
> 6 7 8 9 10
> 11 12
>
> How to do so ?
<snip>


Try this (not tested, you may have to adjust it)

<?php
$received = 12;

echo '<table>';
$count = 1;
while ($count <= $received) {
if (($count % 5) == 1) echo '<tr>';
echo "<td>$count</td>";
if (($count % 5) == 0) echo '</tr>';
++$count;
}
if (($count % 5) != 1) { // generate empty cells
while ($count++ % 5) echo '<td>&nbsp;</td>';
echo '</tr>';
}
echo '</table>';

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация