0
我有一個代碼,將生成一個年份表,每個年份分成5年組。如何將每年的每個數據放在其各自的列中?把每年的數據放在5年組
這就是我到目前爲止。
$chunkSize = 5;
$starting_year = 2006;
$ending_year = date("Y");
for($starting_year; $starting_year <= $ending_year; $starting_year++) {
$years[] = $starting_year;
}
for($i = 0; $i < count($years); $i+=5)
{
echo "<table class='table table-striped table-bordered'>";
echo '<thead><tr>';
echo '<th class="text-center">'.implode('<th class="text-center">', array_slice($years, $i, $chunkSize)).'</th>';
echo '</tr></thead>';
echo '<tr>';
$result= $myDB->query("SELECT total FROM ".$myDB->prefix("statistics")." WHERE year='$years[$i]'") or die(mysql_error());
$row = $myDB->fetchArray($result);
$total=$row['total'];
//echo "<td class='text-center'>".$total."</td>";
echo '<th class="text-center">'.implode('<th class="text-center">', array_slice($total, $i, $chunkSize)).'</th>';
echo '</tr>';
}
echo "</table>";
期望的結果
2016 2017
total total
2011 2012 2013 2014 2015
total total total total total
2006 2007 2008 2009 2010
total total total total total
謝謝你的答案..工作很好..有一個愉快的一天 – blackrx