Can someone help me with this array that I have? I want to create a table that is a maximum of 5 columns and a maximum of 15 rows. If there are only 4 rows, for example, then only 4 rows should be shown instead of the 15. If there are only 3 cells that have data then the the remaining 2 should be padded with $nbsp;
.
Here is my sample array:
Array
(
[0] => Array
(
[name] => test1
[item_id] => 1
)
[1] => Array
(
[name] => test2
[item_id] => 2
)
[2] => Array
(
[name] => test3
[item_id] => 3
)
[3] => Array
(
[name] => test4
[item_id] => 4
)
[4] => Array
(
[name] => test5
[item_id] => 5
)
[5] => Array
(
[name] => test6
[item_id] => 6
)
)
My data repeats if there is a new row added. This is my issue at present.
$row = count( $array ) / 5;
$col = 5;
echo'<table border="1" width="700">';
for( $i = 0; $i < $row; $i++ )
{
echo'<tr>';
for( $j = 0; $j < $col; $j++ ) {
if( ! empty( $array[$j] ) ) {
echo '<td>'.$array[$j]['item_id'].'</td>';
}
}
echo'</tr>';
}
echo'</table>';