rodfarrell Posted April 12, 2011 Share Posted April 12, 2011 I need to extract shopping cart transaction information from a database, convert it to json format and send to another DB. Because the fields are not a direct match the calculated values are first bing put into variables. I'm extracting the line items from the database into an array and looping through the array to get each line item which I want to then insert into another array as a sub array. By the way, I'm new at PHP so be gentle. The first step I've coded as: foreach ($oit_array as $inner1) { // Check type if (!is_array($inner1)) {$inner1 = array($inner1);} $lineprice+=$inner1[orderitem_price]; //calculate amounts required in variables $linepriceinc=$inner1[orderitem_price]+($inner1[orderitem_tax]/$inner1[orderitem_quantity]); if($inner1[orderitem_tax]==0){$linetaxrate+=0;} else $linetaxrate=($inner1[orderitem_final_price]-$inner1[orderitem_tax])/$inner1[orderitem_tax]; $linetaxtotal+=$inner1[orderitem_tax]; $orderqty+=$inner1[orderitem_quantity]; $productname=$inner1[orderitem_name]; $qtyshipped+=$inner1[orderitem_quantity]; $totallineamount+=$inner1[orderitem_final_price]-$inner1[orderitem_tax]; $totallineamountinc+=$inner1[orderitem_final_price]; $unitofmeasure="Units"; $linearray[] = array("LinePrice"=>$lineprice, "LinePriceInc"=>$linepriceinc, "LineTaxCode"=>"GST", "LineTaxRate"=> $linetaxrate, "LineTaxTotal"=> $linetaxtotal, "OrderQty"=> $orderqty, "ProductName"=> $productname, "QtyShipped"=> $orderqty, "TotalLineAmount"=> $totallineamount, "TotalLineAmountInc"=>$totallineamountinc, "UnitOfMeasure"=>"Units"); I then reference the array as $linearray as follows: //Create Array $salesarray= array ("type"=> "TCashSale", "fields"=>array ("CustomerName"=>$customername, "ShipToDesc"=>$shiptodesc, "Lines"=> array("type"=> "TCashSaleLine", "fields"=> $linearray)), "SalesPayments"=>array("type"=>"TSalesPayments", "fields"=>array("Amount"=> $amount, "PayMethod"=> $paymentmethod))); The problem that I have is that the resulting array contains square brackets around the "linearray" data like so: {"type":"TCashSale","fields":{"CustomerName":"Cash Customer","ShipToDesc":"Rod Farrell\n\r1234 Short St\n\r\n\rSlackville Queensland 4001","Lines":{"type":"TCashSaleLine","fields":[{"LinePrice":54.54545,"LinePriceInc":54.54545, What am I doing wrong?? Quote Link to comment Share on other sites More sharing options...
rodfarrell Posted April 12, 2011 Author Share Posted April 12, 2011 OK I get to give myself a bid "DOH" here. What I thought was the problem is not a problem, the issue was elsewhere. Sorry for being such a newbie. Rodf 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.