I'm trying to write a simple SQL query that passes into php.
I have 2 tables 1 containing orders and the other containing individual items in a order.
So the statement needs to return the order details and the items for that order.
I have these tables:
order
order_items
So my guess was:
however what gets returned is 2 arrays:
which makes it look like 2 orders, where as I want the order details
followed by all the items in that order
and
to come out a a single array for that order.
Can anyone help me work out what the SQL would need to do this please?
I have 2 tables 1 containing orders and the other containing individual items in a order.
So the statement needs to return the order details and the items for that order.
I have these tables:
order
Code:
ID | user_id | date | amount | order_type
order_items
Code:
ID | order_id | item | price | quantity
So my guess was:
Code:
SELECT * FROM order
LEFT JOIN order_items
ON order.ID = order_items.order_id
AND order.user_id = "0"
if($orders_result){
$orders_numRows = mysql_num_rows($orders_result);
for($i=0; $i<$orders_numRows; $i++){
$orders[$i] = mysql_fetch_assoc($orders_result);
}
}
however what gets returned is 2 arrays:
Code:
Array
(
[0] => Array
(
[ID] => 0
[user_id] => 0
[date] => 2007-02-08
[amount] => 63
[order_type] => Test
[order_id] => 0
[item] => 12B444
[price] => 10
[quantity] => 2
)
[1] => Array
(
[ID] => 1
[user_id] => 0
[date] => 2007-02-08
[amount] => 63
[order_type] => Test
[order_id] => 0
[item] => 345AA1
[price] => 43
[quantity] => 1
)
Code:
[ID] => 1
[user_id] => 0
[date] => 2007-02-08
[amount] => 63
[order_type] => Test
[order_id] => 0
Code:
[item] => 345AA1
[price] => 43
[quantity] => 1
Code:
[item] => 12B444
[price] => 10
[quantity] => 2
Can anyone help me work out what the SQL would need to do this please?