<?php /* * 此文件是存放部门的默认满意度 * 即软件学院的满意度 */ for($i=1;$i<=15;$i++){ $result3=$pdo->query("select * from tb_question where s_ID=$i"); $total=$result3->rowCount();//获取总记录数 $result4=$pdo->query("select * from tb_question where s_ID=$i and satisfed=1"); $total1=$result4->rowCount();//获取满意的记录数 $satisfed=($total1/$total)*100; $satisfed=(integer)$satisfed."%"; $result5=$pdo->query("select s_ID,s_name from tb_section where s_ID=$i"); foreach ($result5 as $row) {
只需在sql中就可完成,拿出来反倒麻烦了select s_name, sum(if(satisfed=1,1,0))/count(*)*100 as satisfed from tb_question a, tb_section b where a.s_ID=b.s_ID GROUP by a.s_ID ORDER by 2 desc
数据库可以用order byphp里可以用sort之类排序数组
select * from user order by id;//
查询数据的时候数据库语句中加个排序的方法就行了,select * from 表名 order by 某字段(这字段就是你计算出来的满意度)
些么的,这么简单的问题也发上来浪费大家的时间,你不能把SQL语句学完整了再来发帖么?
兄弟. 你这问题 博大精深.说深不深,说不深也深,简单点的数据库 order by 就能搞定. 复杂点的.链上几个表才能搞定. PHP方面也就只是 foreach就能出来. 如果没有采用数据库..那就要看你的数据存放在那里了....这个假设太多太多.小弟我就不写了.
/*
* 此文件是存放部门的默认满意度
* 即软件学院的满意度
*/
for($i=1;$i<=15;$i++){
$result3=$pdo->query("select * from tb_question where s_ID=$i");
$total=$result3->rowCount();//获取总记录数
$result4=$pdo->query("select * from tb_question where s_ID=$i and satisfed=1");
$total1=$result4->rowCount();//获取满意的记录数
$satisfed=($total1/$total)*100;
$satisfed=(integer)$satisfed."%";
$result5=$pdo->query("select s_ID,s_name from tb_section where s_ID=$i");
foreach ($result5 as $row)
{
echo $row[s_name]." 满意度:".$satisfed."<br>";
}
}
?>
这是就是满意度 但是不知道咋去实现关联各个部门和实现排行榜
from tb_question a, tb_section b
where a.s_ID=b.s_ID
GROUP by a.s_ID
ORDER by 2 desc