mihai123 has given you a query that generates one big recordset with all orders and orderlines. I prefer to use your original idea of one query to capture the orders and a second to capture the orderlines. It is a little bit tidier to handle and allows the early identification of errors. But back to handling the array you have.
[PHP]//Not necessary but good practice
$lines = array();
$custorder = array();
foreach($record as $order){
$id = $order['order_id'];
if(!array_key_exists($id,$lines){ #is it a new order number?
$lines[$id]= 0; #New id flag
//Collect the basic order details
$custOrder[$id]['name'] = $order['delivery_name'];
//etc
}
else{ #Collect the order lines
$lines[$id] ++; #increment the no of lines ordered
$custOrder[$id]['model'.$lines[$id]] = $order['products_model'];
$custOrder[$id]['quantity'.$lines[$id]] = $order['products_quantity'];
//etc
}
}[/PHP]This is off the top of my head so excuse the syntax and there are certainly other methods. But you should end up with a 2d array of the format
- Array(id=>first_order_id(
-
Array(name=>delivery_name,.. etc, model1=>orderline,quantity1=>quantity,
-
model2=>orderline,quantity2=>quantity etc)
-
id=>second_order_id Array(second order details) .. 3rd() etc)