日期:2014-05-16 浏览次数:20525 次
SELECT `chengji`,count(*) FROM `table` GROUP BY `chengji`
$sql = SELECT `chengji`,count(*) AS count FROM `table` GROUP BY `chengji`;可以得到类似这样的数组
$rs = mysql_query($sql);
while($row = mysql_fetch_assoc($rs)) {
$res[$row['chengji']] = $row['count'];
}
print_r($res);
Array
(
[及格] => 4
[不及格] => 1
[良好] => 3
)
$res[''] = '数量';
$head = array('', '不及格', '及格', '良好');
echo '<table>';
echo '<tr><th>' . join('</th><th>', $head) . '</th></tr>';
echo '<tr>';
foreach($head as $v) echo '<td>' . (isset($res[$v]) ? $res[$v] : '') . '</td>';
echo '</tr></table>';
<?php
date_default_timezone_set("PRC");
echo "当前月份是".date("m")."\n";
echo "本月初日期是".date("m")."-01\n";
echo "本月未日期是".date("m")."-".date("t")."\n";
?>