output results from 2 mySQLtables
I have 2 tables in my mySQL database csm
and csmproducts
.
Table csm stores the customer info and table csmproducts stores the products they ordered.
"Order_ID" is the common variable in both tables.
I have written a query which pulls data from both tables.
My query looks like this:
$query = "SELECT c.*, p.Product_SKU from csm c, csmproducts p where c.Order_ID = p.Order_ID and c.Order_Status='Awaiting Fulfillment' group by Order_ID order by Order_ID DESC LIMIT $startrow, 50";
$numresults=mysql_query($query);
$numrows=mysql_num_rows($numresults);
}
The trouble I am having is that if one order (hence one Order_ID) has multiple products in it , only the first product is showing.
What do I need to do so that where {$row['Product_SKU']}
gives me only the first product for a particular Order_ID
, that I am able to pull all the Product_SKUs
for that particular Order_ID
?
For example Order_ID 5558
has 3 products associated with it (DSC-3433, ASD-6454, UFY-7383)
Currently the output looks like this (showing just the first item the customer orderd)
Order ID: 5558 开发者_如何学C
Product SKU: DSC3433
I would like to see it like this:
Order ID: 5558
Product SKU: DSC-3433, ASD-6454, UFY-7383
That is: all 3 products associated with that Order_ID
to be shown.
Thanks in advance for the assistance.
USE GROUP_CONCAT
with exlplanation
精彩评论