数据库联合查询输出数量
用tp方法查询班级表,同时在表内输出学生人数
$db_clas = M('clas');
$db_stu = M('stu');
$data_clas = $db_clas->select();
//foreach 循环
foreach($data_clas as $item=>$value){
$count = $db_stu->where('clas_id='.$value['id'])->count();
$data_clas[$item]['count']=$count; //在查询的结果中添加字符段
}
//for 循环
$count =$db_clas->count();
for ($i=0;$i<$count;$i++){
$data[$i]['count']=$db_stu->where(array('clas_id'=>$data[$i]['id']))->count();
}