I need some help, I am trying to create a dynamic HTML table that will display some results from a nested array.
My array will always be setup like this:
Array
(
[column_label] => Size No.
[column_data] => Array
(
[0] => Array
(
[column_cell] => #3
)
[1] => Array
(
[column_cell] => #3.5
)
[2] => Array
(
[column_cell] => #4
)
[3] => Array
(
[column_cell] => #4.5
)
)
)
Array
(
[column_label] => Approx. Diameter Inches
[column_data] => Array
(
[0] => Array
(
[column_cell] => 3/32"
)
[1] => Array
(
[column_cell] => 7/64"
)
[2] => Array
(
[column_cell] => 1/8"
)
[3] => Array
(
[column_cell] => 9/64"
)
)
)
Array
(
[column_label] => Approx. Diameter mm
[column_data] => Array
(
[0] => Array
(
[column_cell] => 2.38
)
[1] => Array
(
[column_cell] => 2.78
)
[2] => Array
(
[column_cell] => 3.18
)
[3] => Array
(
[column_cell] => 3.57
)
)
)
Array
(
[column_label] => Catalog No.
[column_data] => Array
(
[0] => Array
(
[column_cell] => 32030
)
[1] => Array
(
[column_cell] => 32035
)
[2] => Array
(
[column_cell] => 32040
)
[3] => Array
(
[column_cell] => 32045
)
)
)
I need to go through each [column_data] array and prepare them to display as table cells in my table.
For example a row in my table should include table cells from the column_data array with a key of 0. The next row in my table will include table cells from the column_data array with a key of 1 and so on.
Hope this makes sense, this way Im sure the cells will always correspond to Column_label table heading and be displayed vertically in cells.
Here is my failed attempt (unfinished):
<?php if ($product_table) {
//Setup empty arrays
$products = array();
$labels = array();
$data = array();
$column_cells = array();
foreach($product_table as $product) {
//echo '<pre>';
//print_r($product);
//echo '</pre>';
//echo '<th>' . $product['column_label'] . '</th>';
$products[] = $product;
$labels[] = $product['column_label'];
$data[] = $product['column_data'];
foreach ($product['column_data'] as $column_data) {
$column_cells[] = $column_data;
}
}
?>
<table class="table">
<tr>
<?php foreach($labels as $label) {
echo '<th>' . $label . '</th>';
} ?>
</tr>
<?php foreach($products as $product) { ?>
<tr>
<?php
echo '<pre>';
print_r($product);
echo '</pre>';
?>
</tr>
<?php } ?>
</table>
<?php } ?>
