The following script works but I need to modify it.
I am basically pulling open sales order information from a MySQL database and returning it so the order # becomes a hyperlink.
All works well when the order only contains a single sku/quantity purchase, which is a single row result from the database. In the case where 2 or more items are purchased on a single order...I get a line for each and I need them as an aggregate.
Current Result Example -
14 Bob Smith Part# - 9iron Qty-1
14 Bob Smith Part# - 3wood Qty-1
What I need is
14 Bob Smith Part# - 9iron Qty-1 , Part# - 3wood Qty-1
Any help on this would be greatly appreciated.
Thanks,
Kurt
<?php
include('database.php');
$query = "SELECT purchase.id, purchase.firstname, purchase.lastname, purchased.sku, purchased.quantity
FROM
purchase
LEFT JOIN
purchased
ON
purchase.id = purchased.purchase
WHERE
purchase.closed <> 'C'";
$result = mysql_query($query) or die ( mysql_error ());
if (mysql_num_rows($result) > 0) {
echo "<table cellpadding=10 border=1>";
while(list($a,$b,$c,$d,$e) = mysql_fetch_row($result)) {
echo "<tr>";
echo "<td><a href='/test.php?value=$a'> $a </a> - $b $c Part# - $d Qty - $e</td>";
echo "</tr>"; }
echo "</table>";
}
?>
Getting Aggregate of Rows
Moderators: egami, macek, gesf
-
- New php-forum User
- Posts: 31
- Joined: Mon Mar 28, 2011 7:52 am
I appreciate the post back. I have looked at several solutions like merging the rows through MySQL, storing the rows as variables and have not seen a really good example of how to do this yet. Still searching. I appreciate the direction.