以數據庫字段分組顯示數據的sql語句(具體引見)。本站提示廣大學習愛好者:(以數據庫字段分組顯示數據的sql語句(具體引見))文章只能為提供參考,不一定能成為您想要的結果。以下是以數據庫字段分組顯示數據的sql語句(具體引見)正文
<?php
$dsn = "mysql:host=localhost;dbname=group";
$db = new PDO($dsn, 'root', '');
$db->exec('set names utf8');
$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);
//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]);
}