Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Getting Aggregate of Rows

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Getting Aggregate of Rows

Postby coderneeded » Thu May 30, 2013 5:21 am

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>";
}

?>
coderneeded
New php-forum User
New php-forum User
 
Posts: 31
Joined: Mon Mar 28, 2011 7:52 am

Re: Getting Aggregate of Rows

Postby johnj » Thu May 30, 2013 6:09 am

if you have more than one result, save the first one to a variable (e.g. $line) and keep attaching the subsequent ones to it and as soon as you are done, just display this variable.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Getting Aggregate of Rows

Postby coderneeded » Thu May 30, 2013 6:15 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.
coderneeded
New php-forum User
New php-forum User
 
Posts: 31
Joined: Mon Mar 28, 2011 7:52 am


Return to PHP coding => General

Who is online

Users browsing this forum: Google Feedfetcher, Strider64 and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.