Forum Moderators: coopster
col1 col2 col3 col4 col5 ... col12
1 2 3 4 5 12
1 3 4 12
1 2
That is, I want to print "1" in the first column, "2" in the second column etc, indicating the months as extracted from a mysql database, with "blanks" where there are no records in that month
data array looks like
(1,2,,3,4,,5,12)
(1,3,4,,12)
(1,2)
The info is coming from an sql query which selects distinct month(date) where year ="2007".
I have tried all sorts of loops, for $i's, counting.. and I can't get the thing to loop, missing out where there is no number for that column.
This prints them out fine in columns, but when a month is missing, it doesn't skip a column...
<table width="100%" border="0">
<tr>
<?php
$query = GetModelsMonths($year);
if ($modelMonths = $db->get_results($query)) {
foreach ($modelMonths as $modelMonth) {?>
<td><?php echo $modelMonth->month;?></td>
<?php
} // end foreach
} // end if
?>
</tr>
</table>
Thanks
Thanks - will try your method as well.
K
How I did it
<tr>
<?php
// use mysql group_concat to get back an array of months
$query = GetMonthsConcat($model,$modelYear->year);
if ($modelMonths = $db->get_results($query)) {
foreach ($modelMonths as $months) {
$month_array = explode(",",$months->months);
for ($y=1;$y<=12;$y++) {
if(in_array($y,$month_array)) {?>
echo "<td>".$y;?>."</td>";0
} else {
echo "<td class='missing'> </td>";
}
} // end for y
} // end foreach
} // end if?>
</tr>
Thanks