Php 使用多维数组按类别分组和显示MySQL结果

Php 使用多维数组按类别分组和显示MySQL结果,php,mysql,Php,Mysql,我有以下脚本,它从MySQL查询创建多维数组,并根据以下类别打印结果: 脑脊液(感染)葡萄糖蛋白质(斑点尿)血气碳酸氢盐(液体)pH(液体)氧分压(张力)(pO2)肌酐清除率肌酐(液体)肌酐(24小时尿) 这样做,然后在最后一个foreach循环中访问添加的列的正确方法是什么 $row['lab_test_pk'].','.$row['lab_test'].','.$row['interval']; 试着用上面的一行。要使用@N.M.N提供的零件溶液追加。,我有以下工作: while ($ro

我有以下脚本,它从MySQL查询创建多维数组,并根据以下类别打印结果:

脑脊液(感染)
葡萄糖
蛋白质(斑点尿)
血气
碳酸氢盐(液体)
pH(液体)
氧分压(张力)(pO2)
肌酐清除率
肌酐(液体)
肌酐(24小时尿)

这样做,然后在最后一个foreach循环中访问添加的列的正确方法是什么

$row['lab_test_pk'].','.$row['lab_test'].','.$row['interval'];

试着用上面的一行。要使用@N.M.N提供的零件溶液追加。

,我有以下工作:

while ($row = mysql_fetch_assoc($result)){

    $test_groups[$row['group_name']][] = $row['lab_test_pk'].','.$row['lab_test'].','.$row['interval'];

  }

  foreach($test_groups as $group_name => $tests){
    echo '<strong>' . $group_name . '</strong><br />';
    foreach($tests as $test){
        list($test_pk, $test_name, $test_interval) = explode(',', $test);
        echo $test_pk . '<br />';
        echo $test_name . '<br />';
        echo $test_interval . '<br />';
    }
    echo '<p>';
}
while($row=mysql\u fetch\u assoc($result)){
$test_groups[$row['group_name']][]=$row['lab_test_pk'],'.$row['lab_test'],'.$row['interval'];
}
foreach($test\u groups as$group\u name=>$tests){
回显“”.$group_name.”
; foreach($tests作为$test){ 列表($test_pk,$test_name,$test_interval)=分解(“,”,$test); echo$test_pk.“
”; echo$test_name.“
”; echo$test_interval.“
”; } 回声“”; }
如果您在查询中使用了这些列,则可以$测试组[$row['group\U name']][]=$row['lab\U test'],“$row['lab\U test\U pk'],”,“$row['interval'];在那里的某个地方似乎有一个错误…是的,它附加了其他列OK,但是我如何在最后一个foreach循环中独立访问这些列,例如$test['lab_test']不起作用…$test[1]
$row['lab_test_pk'].','.$row['lab_test'].','.$row['interval'];
while ($row = mysql_fetch_assoc($result)){

    $test_groups[$row['group_name']][] = $row['lab_test_pk'].','.$row['lab_test'].','.$row['interval'];

  }

  foreach($test_groups as $group_name => $tests){
    echo '<strong>' . $group_name . '</strong><br />';
    foreach($tests as $test){
        list($test_pk, $test_name, $test_interval) = explode(',', $test);
        echo $test_pk . '<br />';
        echo $test_name . '<br />';
        echo $test_interval . '<br />';
    }
    echo '<p>';
}