Jump to content

php writes a csv file, need help with array and output


cruzer076

Recommended Posts

Hey guys,

I have a script that writes an order to a CSV file, the problem is I need to add the comment field to the last line of data instead of the header how it is currently written.

 

Here is what we currently have, How do I move it from the header to the data field?

 

$order_fields_1 = array (
                                               array('OrdNum', 'OrdTyp', 'CompNbr', 'CustNum', 'WhsID','CustPurchOrdNum','OrdSrc','EntDate','BillAddress1','BillAddress2','BillCity','BillState','BillZip','BillPhone','ShipToName','ShipToCompany','ShipToAddress1','ShipToAddress2','ShipToCity','ShipToState','ShipToZip','ShipToPhone','Comment'),
                                               array($order->id, 'O', '1',$manual_customer_id,'1',$orderNumber,'W',date('m/d/y')),
                                           );
                                           //$order_fields[] = array("H",$order->id, 'O', '1',$manual_customer_id,'1',$orderNumber,'WB',date('m/d/y'),$fields['address1'],$fields['address2'],$fields['city'],StateCore::getNameById($fields['id_state']),$fields['postcode'],$fields['phone_mobile'],$fields['firstname'],$fields['company'],$fields['ship_address1'],$fields['ship_address2'],$fields['ship_city'],StateCore::getNameById($fields['id_ship_state']),$fields['ship_postcode'],$fields['ship_phone_mobile'],$message[0]['message']);
                                           $order_fields[] = array("H",$order->id, 'O', '1',$manual_customer_id,'1',$orderNumber,'WB',date('m/d/y'), $invoice_address_fields['address1'],$invoice_address_fields['address2'],$invoice_address_fields['city'],StateCore::getNameById($invoice_address_fields['id_state']),$invoice_address_fields['postcode'],$invoice_address_fields['phone_mobile'], $delivery_address_fields['firstname']." ".$delivery_address_fields['lastname'],$delivery_address_fields['company'], $delivery_address_fields['address1'],$delivery_address_fields['address2'],$delivery_address_fields['city'],StateCore::getNameById($delivery_address_fields['id_state']),$delivery_address_fields['postcode'],$delivery_address_fields['phone_mobile'], $message[0]['message']);


                                           $order_fields_2[0] = array('OrdNum', 'OrdSeqNum', 'LineItemTyp', 'ItemNum', 'QtyOrd','UntMeas','','','','','','','','','','','','','','','','','');
                                           $products_in_cart = $cart->getProducts();
                                           if(is_array($products_in_cart)){
                                               $i=1;
                                               foreach($products_in_cart as $cartp){
                                                   $order_fields_2[$i] = array($order->id,$i,'I',$cartp['attributes_small'],$cartp['cart_quantity'],'','','','','','','','','','','','','','','','','','');
		 $order_fields[] = array("D",$order->id,$i,'I',$cartp['attributes_small'],$cartp['cart_quantity'],'','','','','','','','','','','','','','','','','');
                                                   $i++;

                                               }

 

 

 

 

 

Thanks

 

 

 

 

My csv file output is suppose to look like this but with the current code it writes to the H, I need to write it to the last D: where its say C, Comments, Thanks:

H,88,O,1,9610,1,M2834,WB,01/16/13,billaddress1,billaddress2,billtocity,billtostate,billtozip,billtophone,shiptoname,shiptocompany,shiptoadd1,shiptoadd2,shiptocity,shiptostate,shiptozip,shiptophone
D,88,1,I,MB500S,2,,,,,,,,,,,,,,,,
D,88,2,I,EL450MT,1,,,,,,,,,,,,,,,,
D,88,3,I,EL450BS,1,,,,,,,,,,,,,,,,
D,88,4,C,Comment,0,,,,,,,,,,,,,,,,

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.