PHP Code:
$MeasureArray = array();
$Columns = array(
'measurement_type' => 'Measurement Type',
'nose' => 'Nose',
'n6' => 'Nose 6"',
'n12' => 'Nose 12"',
'n24' => 'Nose 24"',
'n36' => 'Nose 36"',
'n48' => 'Nose 48"',
'center' => 'Center 12"',
't48' => 'Tail 48"',
't36' => 'Tail 36"',
't24' => 'Tail 24"',
't12' => 'Tail 12"',
't6' => 'Tail 6"',
'tail' => 'Tail"'
);
$ColumnsLeft = array_keys($Columns);
$FinalColumns = array();
foreach($measure as $m){
foreach($ColumnsLeft as $Key => $Value){
if($m->$Value != ""){
unset($ColumnsLeft[$Key]);
$FinalColumns[$Value] = $Columns[$Value];
}
}
if(empty($Columns)){
break;
}
}
echo '<table>';
echo '<tr>';
foreach($FinalColumns as $Name){
echo '<th>' . $Name . '</th>';
}
echo '</tr>';
foreach($measure as $m){
echo '<tr>';
foreach($FinalColumns as $Key => $Name){
echo '<td>';
echo $m->$Key;
echo '</td>';
}
echo '</tr>';
}
echo '</table>';
Here's the full code I used to test with, as I don't have data in the database etc:
PHP Code:
<?php
class Measure{
public $measurement_type = 'a', $nose, $n6, $n12, $n24, $n36, $n48, $center, $t48, $t36, $t24, $t12, $t6, $tail;
function __construct($nose, $n6, $n12, $n24, $n36, $n48, $center, $t48, $t36, $t24, $t12, $t6, $tail){
$this->nose = $nose;
$this->n6 = $n6;
$this->n12 = $n12;
$this->n24 = $n24;
$this->n36 = $n36;
$this->n48 = $n48;
$this->center = $center;
$this->t48 = $t48;
$this->t36 = $t36;
$this->t24 = $t24;
$this->t12 = $t12;
$this->t6 = $t6;
$this->tail = $tail;
}
}
$measure = array(
new Measure(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, '', 12, 13),
new Measure(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, '', 12, 13),
new Measure(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, '', 12, 13),
new Measure(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, '', 12, 13)
);
$MeasureArray = array();
$Columns = array(
'measurement_type' => 'Measurement Type',
'nose' => 'Nose',
'n6' => 'Nose 6"',
'n12' => 'Nose 12"',
'n24' => 'Nose 24"',
'n36' => 'Nose 36"',
'n48' => 'Nose 48"',
'center' => 'Center 12"',
't48' => 'Tail 48"',
't36' => 'Tail 36"',
't24' => 'Tail 24"',
't12' => 'Tail 12"',
't6' => 'Tail 6"',
'tail' => 'Tail"'
);
$FinalColumns = array();
foreach($measure as $m){
foreach($Columns as $Key => $Value){
if($m->$Key != ""){
unset($Columns[$Key]);
$FinalColumns[$Key] = $Value;
}
}
if(empty($Columns)){
break;
}
}
echo '<table>';
echo '<tr>';
foreach($FinalColumns as $Name){
echo '<th>' . $Name . '</th>';
}
echo '</tr>';
foreach($measure as $m){
echo '<tr>';
foreach($FinalColumns as $Key => $Name){
echo '<td>';
echo $m->$Key;
echo '</td>';
}
echo '</tr>';
}
echo '</table>';
Bookmarks