mainstreetop Posted June 27, 2010 Share Posted June 27, 2010 I am having a difficult time figuring out how to retrieve the information I need. I have an ORDERS table that contains an orderId, userId, productNumber, quantity and price for that orderId. I am JOINING other tables to get the company/user/shipping info. I'm trying to create a table that displays the items within each orderId. So, I figured arrays would be the best way to store the data. One for the order header information (static info) and one for the order details (different items in each order). I understand how to create each array. I'm just not sure how to arrange the arrays to output to a table. I'm guessing it's a FOR LOOP within a FOR LOOP, but can't quite get the login. Here's my code so far... // create order header array // the GROUP BY is intended to give me the unique orderId $q = mysql_query(" SELECT orders.*, ship.*, company.*, user.* FROM orders JOIN company ON orders.companyId = company.companyId JOIN ship ON orders.shipId = ship.shipId JOIN user ON orders.userId = user.userId GROUP BY orderId ") or die (mysql_error()); while($row = mysql_fetch_array($q)) { foreach($row as $key => $value) { if(is_string($key)) $orderHeader[$key][] = $value; } } // and the orderDetails array // the item table gives me product description information // this array may, for example, contain one or two items per order $q = mysql_query(" SELECT orders.*, item.* FROM orders JOIN item ON orders.productNumber = item.ProductNumber ") or die(mysql_error()); while($row = mysql_fetch_array($q)) { foreach($row as $key => $value) { if(is_string($key)) $orderDetails[$key][] = $value; } } Any thoughts on how to get the items within each orderId grouped together for display? Thank you. Mike Link to comment https://forums.phpfreaks.com/topic/205967-creating-echoing-multi-dimensional-array/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.