foreach trouble
Posted: Mon Apr 12, 2010 7:07 pm
I have a do loop for customer order data - assuming each person ordered ONE item, their "order" would contain 3 lines of text, each with a header. The first line is "H" text, the second (which is the item information) line is "D" text, and the third line (which contains the total amount) is "T" text. So, for each customer, their information would be as such:
H tab delimited information about customer
D tab delimited information about item ordered
T tab delimited information about total order
However, if a customer ordered 3 items, then it would need to be like this:
H tab delimited information about customer
D tab delimited information about 1st item ordered
D tab delimited information about 2nd item ordered
D tab delimited information about 3rd item ordered
T tab delimited information about total order
I have having trouble with my foreach on the item information -- here's my current code:
Instead of just repeating that "D" line for each item number associated with a particular customer, it's still running through each - so for a customer who has 2 items, for instance, it's giving me this:
H
D
T
H
D
T
Instead of just
H
D
D
T
Hope that's clear...thanks in advance!
Virginia
H tab delimited information about customer
D tab delimited information about item ordered
T tab delimited information about total order
However, if a customer ordered 3 items, then it would need to be like this:
H tab delimited information about customer
D tab delimited information about 1st item ordered
D tab delimited information about 2nd item ordered
D tab delimited information about 3rd item ordered
T tab delimited information about total order
I have having trouble with my foreach on the item information -- here's my current code:
Code: Select all
$items=array($row_rsCustomerOrders['sku_item_number']);
if ($totalRows_rsCustomerOrders) {
do {
fputs($handleWriteNM,"H\torder #\tcust order\tname\taddress 1\taddress 2\tcity\tstate\tzip code\tcountry\tphone number\temail\tshipping method\r\n"); // write 1st headers in output
fputs($handleWriteNM,"H\t" . $row_rsCustomerOrders['invoice_number'] . "\t" . $row_rsCustomerOrders['order_id'] . "\t" . $row_rsCustomerOrders['shipping_first_name'] . ' ' . $row_rsCustomerOrders['shipping_last_name'] . "\t" . $row_rsCustomerOrders['shipping_address_1'] . "\t" . $row_rsCustomerOrders['shipping_address_2'] . "\t" . $row_rsCustomerOrders['shipping_city'] . "\t" . $row_rsCustomerOrders['shipping_state'] . "\t" . $row_rsCustomerOrders['shipping_zip'] . "\t" . $row_rsCustomerOrders['shipping_country'] . "\t" . $row_rsCustomerOrders['shipping_day_phone'] . "\t" . $row_rsCustomerOrders['marketplace_email'] . "\tUSPS\r\n");
foreach($items as $key => $value)
{
fputs($handleWriteNM,"D\torder #\titem #\tdescription\tquantity\tprice\r\n"); // write 2nd headers in output
fputs($handleWriteNM,"D\t" . $row_rsCustomerOrders['invoice_number'] . "\t" . $value . "\t" . $row_rsCustomerOrders['description'] . "\t" . $row_rsCustomerOrders['qty_won'] . "\t" . $row_rsCustomerOrders['unit_bid'] . "\r\n");
}
fputs($handleWriteNM,"T\torder #\tsubtotal\tshipping\ttax\tdiscount\ttotal\r\n"); //write 3rd headers in output
fputs($handleWriteNM,"T\t" . $row_rsCustomerOrders['invoice_number'] . "\t" . $row_rsCustomerOrders['shipment_subTotal'] . "\t" . $row_rsCustomerOrders['shipping_charge'] . "\t" . $row_rsCustomerOrders['total_tax'] . "\t" . $row_rsCustomerOrders['discount'] . "\t" . $row_rsCustomerOrders['total_invoice_amount'] . "\r\n");
}
while ($row_rsCustomerOrders=mysql_fetch_assoc($rsCustomerOrders));
}H
D
T
H
D
T
Instead of just
H
D
D
T
Hope that's clear...thanks in advance!
Virginia