《MYSQL数据库以数据库字段分组显示数据的sql语句(详细介绍)》要点:
本文介绍了MYSQL数据库以数据库字段分组显示数据的sql语句(详细介绍),希望对您有用。如果有疑问,可以联系我们。
$sql = "select conf_id from `group` group by conf_id";
//$pre = $db->prepare($sql);
//$result_arr = array();
$pre = $db->query($sql);
$result_arr = $pre->fetchAll(PDO::FETCH_ASSOC);MYSQL必读
//print_r ($result_arr);
foreach ($result_arr as $v)
{
echo $v[conf_id]."<br>";
$vv = $v[conf_id];
$re = array();
$sql1 = "select * from `group` where conf_id = '$v[conf_id]' order by time";
$sql2 = "select * from `group` where conf_id = '$v[conf_id]' order by time DESC";
$rs1 = $db->query($sql1);
$rs2 = $db->query($sql2);
$re1[$vv] = $rs1->fetchAll(PDO::FETCH_ASSOC);
$re2[$vv] = $rs2->fetchAll(PDO::FETCH_ASSOC);
print_r($re1[$vv][0]);
print_r($re2[$vv][0]);
}
MYSQL必读
转载请注明本页网址:
http://www.vephp.com/jiaocheng/3726.html