craygo Posted November 27, 2006 Share Posted November 27, 2006 I have a few tables That i want to report on. I want to output them into 2 groups. This is for a packing slip. Example I have an order. It is going to 2 different addresses and using multiple shipping methods. I want to group the report by shipping address(already done) but also want to group it buy shipping method under it. so it would look like thisSome street fedex P1 detail 1 detail 2 fedex P2 detail 3 detail 4Next Street UPS Overnight detail 3 detail 4here is my query which I think is fine. Just need it to output corectly to the page[code]$reports = "SELECT orderdetails.DetailNum AS detnum, shipping.ShipName AS shipname, orderdetails.ShipID AS shipid, shipmethod.ShipMethod AS shipmeth, orderdetails.ShipMethID AS shipmid, orderdetails.OrderID AS ordid FROM orderdetails JOIN shipping ON orderdetails.ShipID = shipping.ShipID JOIN orders ON orderdetails.OrderID = orders.OrderID JOIN shipmethod ON orderdetails.ShipMethID = shipmethod.ShipMethID WHERE orderdetails.OrderID = ".$_GET['ordid']." GROUP BY shipping.ShipName, orderdetails.ShipMethID, orderdetails.DetailNum";[/code]ThanksRay Link to comment https://forums.phpfreaks.com/topic/28654-output-2-groups/ Share on other sites More sharing options...
Barand Posted November 27, 2006 Share Posted November 27, 2006 You want ORDER BY, not GROUP BY.GROUP BY is used when you want aggregate totals, averages etc.[code]$reports = "SELECT orderdetails.DetailNum AS detnum, shipping.ShipName AS shipname, orderdetails.ShipID AS shipid, shipmethod.ShipMethod AS shipmeth, orderdetails.ShipMethID AS shipmid, orderdetails.OrderID AS ordid FROM orderdetails JOIN shipping ON orderdetails.ShipID = shipping.ShipID JOIN orders ON orderdetails.OrderID = orders.OrderID JOIN shipmethod ON orderdetails.ShipMethID = shipmethod.ShipMethID WHERE orderdetails.OrderID = ".$_GET['ordid']." ORDER BY shipping.ShipName, orderdetails.ShipMethID, orderdetails.DetailNum"; $res = mysql_query($reports) or die(mysql_error());$prevShipname = '';$prevShipmeth = '';while (list($detnum, $shipname, $shipid, $shipmeth, $shipmid, $ordid) = mysql_fetch_row($res)) { // has shipname changed? // if so assume shipmeth also changes if ($prevShipname != $shipname) { echo "<h3>$shipname</h3>"; echo "<h4>$shipmeth</h4>"; $prevShipname = $shipname; $prevShipmeth = $shipmeth; } elseif ($prevShipmeth != $shipmeth) { echo "<h4>$shipmeth</h4>"; $prevShipmeth = $shipmeth; } echo "$ordid $detnum<br/>"; }?>[/code] Link to comment https://forums.phpfreaks.com/topic/28654-output-2-groups/#findComment-131177 Share on other sites More sharing options...
craygo Posted November 28, 2006 Author Share Posted November 28, 2006 Thanks barand, I will try it out tomorrow when I get to work.Ray Link to comment https://forums.phpfreaks.com/topic/28654-output-2-groups/#findComment-131375 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.