rgb192
asked on
if there is only one row, I want it to be on the second row
if $x<=4 do one row
if $x<=8 && $x>=5 two rows
if $x>=9 && $x<=14 three rows
I need to do
<table>
<tr>
<td>
and I want the items to evenly distributed
with the number of items per row being important
x can be any value 1-14
these are examples:
if $x==5
3 items on first row
2 items on second row
if $x==7
4 items on first row
3 items on second row
if $x==9
3 items on first row
3 items on second row
3 items on third row
if $x== 14
5
5
4
is what I want
the code is correct
but if there is only one row, I want it to be on the second row
so I want either a linebreak or an empty first row
if $x<=8 && $x>=5 two rows
if $x>=9 && $x<=14 three rows
I need to do
<table>
<tr>
<td>
and I want the items to evenly distributed
with the number of items per row being important
x can be any value 1-14
these are examples:
if $x==5
3 items on first row
2 items on second row
if $x==7
4 items on first row
3 items on second row
if $x==9
3 items on first row
3 items on second row
3 items on third row
if $x== 14
5
5
4
is what I want
the code is correct
but if there is only one row, I want it to be on the second row
so I want either a linebreak or an empty first row
<table border="1">
<?php
$x = array('1','2','3','4','5','6','7','8','9','10','11','12');
// count the items in an array
$num = count($x);
switch($num){
case 1: $numrows = 1; break;
case 2: $numrows = 1; break;
case 3: $numrows = 1; break;
case 4: $numrows = 1; break;
case 5: $numrows = 2; break;
case 6: $numrows = 2; break;
case 7: $numrows = 2; break;
case 8: $numrows = 2; break;
}
// TO DO
// handling of more than 9 items
if($num >= 9) $numrows = 3;
{
// how much items do we have left
$itemsleft = $num;
$firstitem = 0;
for($i=$numrows;$i>0;$i--){
echo"<tr><td>";
// first row items
$numitems = ceil($itemsleft/$i);
// substract the items
$itemsleft = $itemsleft - $numitems;
for($j=$firstitem;$j<$firstitem+$numitems;$j++)
echo"<img src=".$x[$j]." />";
$firstitem = $firstitem + $numitems;
echo"</td></tr>";
}
}
?>
</table>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks
Open in new window