3 回答
TA贡献1816条经验 获得超4个赞
你应该试试看 :
foreach($sql_result as $type=> $id){
if(!isset($res[$type])){
$res[$type]=array();
}
array_push($res[$type], $id);
}
这给出了一个这样的数组:
[1] => { [0] => [1], [1] => [2], [2] => [3], [4] => [11]}
现在你应该使用另一个 foreach 循环来输出结果
foreach($res as $type => $arr){
echo $type;
foreach($arr as $id){
echo $id."<br>;
}
}
玩得开心 :)
TA贡献1880条经验 获得超4个赞
请尝试此查询并获取记录;
$sql = 'SELECT type,GROUP_CONCAT(id SEPARATOR ' ') as id FROM ob GROUP BY type';
$result = mysqli_query($db, $sql);
echo "<b>type</b> <b>id</b><br/>";
while($row = mysqli_fetch_assoc($result)) {
echo $row['type'] ."".$row['id']."<br/>";
}
TA贡献1874条经验 获得超12个赞
$x = '';
while($row = mysqli_fetch_assoc($result)){
if($x == $row['x']){do something} else {do something else};
$x = $row['x'];
}
- 3 回答
- 0 关注
- 134 浏览
添加回答
举报