Would be great if anyone can help? I currently have the data below being output by the code at the bottom but ranther than it repeating for each order_product_id I want to build an multi level array from the data.
Current output:
[0] => Array
(
[order_product_id] => 43
[order_id] => 1
[product_id] => 161
[name] => Hoodie
[model] => Hoodie
[quantity] => 1
[price] => 23.9500
[total] => 23.9500
[tax] => 0.0000
[reward] => 0
[option_id] => 141
[option_name] => Hoodie Style
[option_value] => Pull over
)
[1] => Array
(
[order_product_id] => 43
[order_id] => 1
[product_id] => 161
[name] => Hoodie
[model] => Hoodie
[quantity] => 1
[price] => 23.9500
[total] => 23.9500
[tax] => 0.0000
[reward] => 0
[option_id] => 142
[option_name] => Hoodie Colour
[option_value] => Light Pink
)
[2] => Array
(
[order_product_id] => 43
[order_id] => 1
[product_id] => 161
[name] => Hoodie
[model] => Hoodie
[quantity] => 1
[price] => 23.9500
[total] => 23.9500
[tax] => 0.0000
[reward] => 0
[option_id] => 143
[option_name] => Adult Sizes
[option_value] => Ladies Meduim 10-12
)
Desired array where each product has all its options in multi level rather than how the current set up shows it:
[0] => Array
(
[order_product_id] => 43
[order_id] => 1
[product_id] => 161
[name] => Hoodie
[model] => Hoodie
[quantity] => 1
[price] => 23.9500
[total] => 23.9500
[tax] => 0.0000
[reward] => 0
Array
(
[0] => Array
(
[option_id] => 141
[option_name] => Hoodie Style
[option_value] => Pull over
)
[1] => Array
(
[option_id] => 142
[option_name] => Hoodie Colour
[option_value] => Light Pink
)
[2] => Array
(
[option_id] => 141
[option_name] => Adult Sizes
[option_value] => Ladies Meduim 10-12
)
)
)
The current output is being built by this:
$sql = "SELECT site_order_product.*,
site_order_option.order_option_id AS option_id, site_order_option.name AS option_name, site_order_option.value AS option_value
FROM site_order_product
INNER JOIN site_order_option ON site_order_product.order_product_id = site_order_option.order_product_id; ";
$result=mysqli_query($dbh2,$sql);
if($result) {
$row = mysqli_fetch_all($result,MYSQLI_ASSOC);
return $row;
} else {
return false;
}
Thanks for any help!