EatCodePlaySleep
EatCodePlaySleep

Reputation: 58

Multidimensional Array from SQL Table

Here's the my SQL table:

order_id | product_id | deal_title | currency_code | total | date_modified

My Question is how do I make an array in PHP like in the below:

Array
(
    [product_id_num1] => Array
        (
            [order_id]
            [deal_title]
            [currency_code]
            [total]
            [date_modified]
        )
    [product_id_num2] => Array
        (
            [order_id]
            [deal_title]
            [currency_code]
            [total]
            [date_modified]
        )
    [product_id_num3] => Array
        (
            [order_id]
            [deal_title]
            [currency_code]
            [total]
            [date_modified]
        )
etc....
)

Thanks!

Upvotes: 0

Views: 69

Answers (1)

MH2K9
MH2K9

Reputation: 12039

You can try something like below

$arr = array();
while($row = mysqli_fetch_assoc($query_result)) {
    $id = $row['product_id'];
    unset($row['product_id']);
    $arr[$id] = $row;
}

Upvotes: 2

Related Questions