Jump to content

Ouputting Multiple lines with a loop


dootch

Recommended Posts

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 ex
order_id 123456, sku 1234, buyer John Doe
order_id 123456, sku 5678, buyer John Doe
So when I output the data it displays it as two records:
John Doe
Order #123456
sku 1234

John Doe
Order#123456
sku 5678

where I only want it to be one with the two parts listed
John Doe
Order#123456
sku 1234
sku 5678

I 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]
Link to comment
Share on other sites

[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.
Link to comment
Share on other sites

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 set

while($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]
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.