0

我已经从表中检索了一些数据。像数组一样

在此处输入图像描述

我想要数组是..

 $subpro[HardDisk] = array (H1000 => 1200,H500 => 700);
    $subpro[Ip] = array (4IP => 400 , 2IP => 200);
    $subpro[Ram] = array (..);
    $subpro[processor] = array (...);

php代码..

while($row=mysql_fetch_array($res))
    {
        if(sizeof($subpro[$row['category']]>0) 
array_put_to_position($subpro[$row['category']],$row['rate'], 2,$row['name']);
        else
                        $subpro[$row['category']]=array($row['name']=>$row['rate']);                
    }
4

1 回答 1

2

除非我误解了这个问题,否则答案很简单。

$subpro = array();
while($row = mysql_fetch_array($res)) {
  $subpro[$row['category']][$row['name']] = $row['rate'];
}
于 2012-07-04T11:21:42.930 回答