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 />
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号