php - How can I convert record set from database to array?
799
How can I convert record set from database to array?
It has 1 table named:tblproduct
, with the following schema:
product_id | product_name | product_desc | product_price | product_img
When I select data from the database I would like an array in the following format:
$product_array = array(
"105" => array('product_id' => '105', 'product_name' => 'Blackberry 8900',
'product_desc' => '', 'product_price' => '1150.00',
'product_img' => 'products/product5.jpg'),
"106" => array('product_id' => '106', 'product_name' => 'Headphone with mic',
'product_desc' => '', 'product_price'=>'148.85',
'product_img' => 'products/product8.jpg')
);
Best regards
Answer
Solution:
Assuming you are using MySQL (You didn't specify your DBMS) and have a line like:
You can use: