I am trying to write a query that shows me all orders with their options. So far that's done, but when I try to group them by order id it just print a separate row for each option and not the order ID and all its option under it.
I am missing something but can't figure out what is it :)
Here is what I have
$sql = 'SELECT *
FROM `order` RIGHT JOIN `order_option`
on order.order_id=order_option.order_id
where order_status_id = 2
group by order_option.order_option_id';
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
{
print "ID:{$row['order_id']} <br> ".
"OPTION NAME: {$row['name']} <br> ".
"VALUE: {$row['value']} <br> ".
"--------------------------------<br>";
}
echo "Fetched data successfully\n";
mysql_close($conn);
?>
**UPDATE 1**
This is how the query worked now
SELECT
o.order_id,
o.name,
o.value,
GROUP_CONCAT(o.order_id, o.name, o.value SEPARATOR ',') AS Options
FROM `order_option` AS o
LEFT JOIN `order` AS oo on o.order_id = oo.order_id
where oo.order_status_id = 2
group by o.order_id