Hi
I am having some problems with my mysql database and php queries.
I have a simple table (‘database_table’) that stores order details from my online gift shop. The table is set up as follows:
id | order_code | item_code | item_description | name
1 | 56743 | 56AAY | Fruit Bowl | Joe
2 | 56743 | 518VB | Aftershave | Joe
3 | 88932 | 11TQW | Red Mug | Mary
etc…
Each item (defined by item_code and item_description) within the order will be added to a separate row.
On orders such as ‘56743’ (Joe), there are two entries as they have ordered 2 items within the 1 order.
Now my problem is that i want to set up a query that pulls order ‘56743’ from the database and displays all the items within the order.
I have the following PHP code for my query:
$query="SELECT * FROM database_table WHERE order_code='56743'";
$result=mysql_query($query);
mysql_close();
while($row = mysql_fetch_array($result)) {
echo "
<p>Your Order:</p>
<p>Your Name: ".$row['name']."</p>
<p>Your Order Code:".$row['order_code']."</p>
<p>Your Item Codes:".$row['item_code']."</p>
<p>Your Item Descriptions:".$row['item_description']."</p>";
}
This outputs the following:
Your Order:
Your Name: Joe
Your Order Code: 56743
Your Item Codes: 56AAY
Your Item Descriptions: Fruit Bowl
Your Order:
Your Name: Joe
Your Order Code: 56743
Your Item Codes: 518VB
Your Item Descriptions: Aftershave
But i only want it to output the ‘item_code’ and ‘item_description’ more than once if the order has several items, The ‘name’ and ‘order_code’ i only want to be displayed once (so as below:)
Your Order:
Your Name: Joe
Your Order Code: 56743
Your Item Codes: 56AAY
Your Item Codes: 518VB
Your Item Descriptions: Fruit Bowl
Your Item Descriptions: Aftershave
I am quite new to mysql so apologies if this isn’t explained to well and for the length of it!
Thanks in advance for any help
John