GROUP BY 语句怎么用php输出来类
数据库 tabel 中有 `chengji` 字段 内容为 及格 不及格 良好 三种值
页面显示出三种值的统计数
我用
SELECT `chengji`,count(*) FROM `table` GROUP BY `chengji`
$sql = SELECT `chengji`,count(*) AS count FROM `table` GROUP BY `chengji`;<br />$rs = mysql_query($sql);<br />while($row = mysql_fetch_assoc($rs)) {<br /> $res[$row['chengji']] = $row['count'];<br />}<br />print_r($res);<br />
Array<br />(<br /> [及格] => 4<br /> [不及格] => 1<br /> [良好] => 3<br />)<br />
$res[''] = '数量';<br />$head = array('', '不及格', '及格', '良好');<br />echo '<table>';<br />echo '<tr><th>' . join('</th><th>', $head) . '</th></tr>';<br />echo '<tr>';<br />foreach($head as $v) echo '<td>' . (isset($res[$v]) ? $res[$v] : '') . '</td>';<br />echo '</tr></table>';<br />
<br /><?php<br />date_default_timezone_set("PRC");<br /><br />echo "当前月份是".date("m")."\n";<br />echo "本月初日期是".date("m")."-01\n";<br />echo "本月未日期是".date("m")."-".date("t")."\n";<br />?><br />