I've been stuck on a problem in displaying SQL data in a desired format for a few days now and was hoping someone might be able to point me in the right direction. I hope I can explain this properly...
I am developing a
WEBSITE for my wife's catering business. What I have is a shopping cart where clients can browse the site and select products which are passed to their cart using $_SESSION. After the client makes selections and confirms desired quantities etc they can SUBMIT their order, and the data is passed to the DB(database).
Each of the selected products are posted to the DB singularily, meaning each item creates another row in the DB, but each has the exact same date/time in the "orderDate" field. (This is my novice way of grouping orders by "date" rather than perhaps a better method of grouping them by "orderID").
This system seems to work ok for most intents and purposes. What I would like to improve upon is how the client (or site admins) view the posted orders. Currently, the client (or admins) can go to their Profile and view their posted orders which are kept on record for their convenience which they can print etc for their own files.
Here's the problem...
I cannot figure out how to group the orders by the "date/time" so they display in same table more resembling a "purchase order" with totals etc for each date, and not a list of every "product" ordered. I have no problem in producing the tables and totals etc. I believe the problem resides in fetching the data properly in perhaps arrays or as I've seen before, [$i] statements?
Below is a snapshot showing how it displays now, to give you an idea:

If image not loading:
IMAGE HERE
This is the PHP code I'm using to fetch the data, and then display it:
Code:
<?php
$connection = @mysql_connect($server, $dbusername, $dbpassword) or die(mysql_error());
$db = @mysql_select_db($db_name,$connection) or die(mysql_error());
$sql ="SELECT * FROM orders ORDER BY orderDate DESC";
$result = @mysql_query($sql,$connection) or die(mysql_error());
$num = mysql_num_rows($result);
while ($sql = mysql_fetch_object($result)) {
$uname = $sql -> username;
$company = $sql -> company;
$order = $sql -> orderNumber;
$date = $sql -> orderDate;
$total = $sql -> orderTotal;
$pqty = $sql -> productQty;
$pname = $sql -> productName;
$pprice = $sql -> productPrice;
$comment = $sql -> comment;
echo'
<table class=orders>
<tr>
<td>
'.$date.'
</td>
<td>
'.$uname.'
</td>
<td>
('.$company.')
</td>
</tr>
<tr class=items>
<td>
'.$pname.'
</td>
<td colspan="2">
'.$pqty.' @ '.$pprice.' = $ '.$total.'
</td>
</tr>
<tr>
<td colspan="3">
'.$comment.'
</td>
</tr>
</table>
';
}
I hope this makes some sense, and look forward to any useful direction.