dootch Posted March 10, 2006 Share Posted March 10, 2006 I currrently dump an orders .txt file of data to a table and want to output them to view in a browser I have that part. My problem is that the if an order has multiple line items is puts it on a different row in the table exorder_id 123456, sku 1234, buyer John Doe order_id 123456, sku 5678, buyer John DoeSo when I output the data it displays it as two records:John DoeOrder #123456sku 1234John DoeOrder#123456sku 5678where I only want it to be one with the two parts listedJohn DoeOrder#123456sku 1234sku 5678I am thinking I need a loop within a loop or something to that effect. Any idea's?? Here's a snippet of the code so far[code]$i=0;while ($i < $num) {$name=mysql_result($result,$i,"recipient_name");$address1=mysql_result($result,$i,"ship_address_1");$address2=mysql_result($result,$i,"ship_address_2");$city=mysql_result($result,$i,"ship_city");$state=mysql_result($result,$i,"ship_state");$zip=mysql_result($result,$i,"ship_postal_code");$order=mysql_result($result,$i,"order_id");$email=mysql_result($result,$i,"buyer_email");$qty=mysql_result($result,$i,"quantity_purchased");$sku=mysql_result($result,$i,"sku");$product=mysql_result($result,$i,"product_name");?><table ><tr> <td><font face="Arial, Helvetica, sans-serif"><? echo "$name"; ?></font></td></tr><tr><td><font face="Arial, Helvetica, sans-serif"><? echo "$address1"; ?></font></td></tr><tr><td><font face="Arial, Helvetica, sans-serif"><? echo "$address2"; ?></font></td></tr><tr><td><font face="Arial, Helvetica, sans-serif"><? echo "$city, $state $zip"; ?></font></td></tr><tr><td><font face="Arial, Helvetica, sans-serif"><? echo "$order"; ?></font></td></tr><tr><td><font face="Arial, Helvetica, sans-serif"><? echo "$email"; ?></font></td></tr><tr><td><font face="Arial, Helvetica, sans-serif"><? echo "$qty $sku $product"; ?></font></td></tr> [/code] Quote Link to comment Share on other sites More sharing options...
mem0ri Posted March 10, 2006 Share Posted March 10, 2006 Yes...you need a loop within a loop......you will need to acquire all records from 1 customer with unique SKUs......then...loop an output of each SKU...then...move on to the next customer. Quote Link to comment Share on other sites More sharing options...
beamerrox Posted March 11, 2006 Share Posted March 11, 2006 [code]while($sys = mysql_fetch_assoc(mysql_query(""))){$name = $sys['recipient_name'];$address1 = $sys['ship_address_1'];$address2 = $sys['ship_address_2'];$city = $sys['ship_city'];$state = $sys['ship_state'];$zip = $sys['ship_postal_code'];$order = $sys['order_id'];$email = $sys['buyer_email'];$qty = $sys['quantity_purchased'];$sku = $sys['sku'];$product = $sys['product_name'];<table ><tr> <td><font face="Arial, Helvetica, sans-serif"><? echo "$name"; ?></font></td></tr><tr><td><font face="Arial, Helvetica, sans-serif"><? echo "$address1"; ?></font></td></tr><tr><td><font face="Arial, Helvetica, sans-serif"><? echo "$address2"; ?></font></td></tr><tr><td><font face="Arial, Helvetica, sans-serif"><? echo "$city, $state $zip"; ?></font></td></tr><tr><td><font face="Arial, Helvetica, sans-serif"><? echo "$order"; ?></font></td></tr><tr><td><font face="Arial, Helvetica, sans-serif"><? echo "$email"; ?></font></td></tr><tr><td><font face="Arial, Helvetica, sans-serif"><? echo "$qty $sku $product"; ?></font></td></tr>}[/code]in my opinion this works better and more efficient. Quote Link to comment Share on other sites More sharing options...
dootch Posted March 14, 2006 Author Share Posted March 14, 2006 OK I am totally lost here I am trying to add the inner loop but its wont work here is what I have. Any idea's?[code]<?include("dbinfo.inc.php");mysql_connect(localhost,$username,$password);@mysql_select_db($database) or die( "Unable to select database");$query="SELECT * FROM orders";$result=mysql_query($query);$num=mysql_numrows($result);// set up query to get all products ordered:$query2="select sku, quantity_purchased, products_name from orders where order_id_id=".$order;$result2=mysql_query($query2);// inner loop result setwhile($inner_row = mysql_fetch_assoc($result2);$i=0;while ($i < $num) {$name=mysql_result($result,$i,"recipient_name");$address1=mysql_result($result,$i,"ship_address_1");$address2=mysql_result($result,$i,"ship_address_2");$city=mysql_result($result,$i,"ship_city");$state=mysql_result($result,$i,"ship_state");$zip=mysql_result($result,$i,"ship_postal_code");$order=mysql_result($result,$i,"order_id");$email=mysql_result($result,$i,"buyer_email");$qty= $inner_row ['quantity_purchased'];$sku= $inner_row ['sku'];$product= $inner_row ['product_name'];?><table ><tr><td><font face="Arial, Helvetica, sans-serif"><? echo "$name"; ?></font></td></tr><tr><td><font face="Arial, Helvetica, sans-serif"><? echo "$address1"; ?></font></td></tr><tr><td><font face="Arial, Helvetica, sans-serif"><? echo "$address2"; ?></font></td></tr><tr><td><font face="Arial, Helvetica, sans-serif"><? echo "$city, $state $zip"; ?></font></td></tr><tr><td><font face="Arial, Helvetica, sans-serif"><? echo "$order"; ?></font></td></tr><tr><td><font face="Arial, Helvetica, sans-serif"><? echo "$email"; ?></font></td></tr><tr><td><font face="Arial, Helvetica, sans-serif"><? echo "$qty $sku $product"; ?></font></td></tr><?++$i;}echo "</table>";?>[/code] Quote Link to comment Share on other sites More sharing options...
keeB Posted March 15, 2006 Share Posted March 15, 2006 [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Any idea's? [/quote]Use XML and the built in XML Parser.. Quote Link to comment Share on other sites More sharing options...
dootch Posted March 15, 2006 Author Share Posted March 15, 2006 I have condensed my code a bit to get anything to work this bit shows the individual order_id's but no product info It is not passing the variable. Still trying but I don't really know enough to get it to work. Please help.[code]<?include("dbinfo.inc.php");mysql_connect(localhost,$username,$password);@mysql_select_db($database) or die( "Unable to select database");$query="select distinct order_id from orders ";$result=mysql_query($query);$num=mysql_numrows($result);$query1="select sku, quantity_purchased, product_name from orders where order_id= " .$result. "";$result1=mysql_query($query1);$num1=mysql_numrows($result1);$i=0;while ($i < $num) {$order=mysql_result($result,$i,"order_id");$qty=mysql_result($result1,$i,"quantity_purchased");$sku= mysql_result($result1,$i,"sku");$product= mysql_result($result1,$i,"product_name");?><table ><tr><td><font face="Arial, Helvetica, sans-serif"><? echo "$order"; ?></font></td></tr><tr><td><font face="Arial, Helvetica, sans-serif"><? echo "$qty $sku $product"; ?></font></td></tr><P CLASS="breakhere"><?++$i;}echo "</table>";?>[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.