Vaishu
Vaishu

Reputation: 2363

create category based array from mysql table using php

I have retrieve some data from table. form array like

enter image description here

I want array is..

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

php code ..

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']);                
    }

Upvotes: 0

Views: 699

Answers (1)

billyonecan
billyonecan

Reputation: 20250

Unless I've misunderstood the question the answer is pretty simple.

$subpro = array();
while($row = mysql_fetch_array($res)) {
  $subpro[$row['category']][$row['name']] = $row['rate'];
}

Upvotes: 2

Related Questions