Issue with mysql loop

Intuit integration.
With create invoice. I am needing to get items from a loop when I create the invoice.

I also tried by creating the loop first and using $items in the invoice create but also get an error. “Format Error. Expect an element of an array or an object.”

Not liking my loop. How can I accomplish this
?

$theResourceObj = Invoice::create([
"TotalAmt" => 200.00, 
    
    "Line" => [
      
$queryitems = 'SELECT * FROM mydatabse',
$query_items  = mysqli_query($con,$queryitems),
while($row = mysqli_fetch_array($query_items)) { 

      [
        "Description"=> "Loop Description", 
        "DetailType"=> "SalesItemLineDetail", 
        "SalesItemLineDetail"=> [
          "TaxCodeRef"=> [
            "value"=> "TAX"
          ], 
          "Qty"=> 1, 
          "UnitPrice"=> 200, 
          "ItemRef"=> [
            "name"=> "Loop Name", 
            "value"=> "5"
          ]
        ], 
        "LineNum"=> 1, 
        "Amount"=> 200.00, 
        "Id"=> "1"
      ],
}
        
    
    ],
    "CustomerRef"=> [
          "value"=> 1
    ],
    "BillEmail" => [
          "Address" => "<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="13767e727a7f53607c7e76647b7661763d707c7e">[email protected]</a>"
    ]
]);

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You can’t put loops inside array literals.

Construct the array incrementally outside the call to Invoice::create().

$invoice = [
    "TotalAmt" => 200.00,
    "CustomerRef"=> [
        "value"=> 1
    ],
    "BillEmail" => [
        "Address" => "<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="61040c00080d21120e0c0416090413044f020e0c">[email protected]</a>"
    ]
];
$lines = []; 
$queryitems = 'SELECT * FROM mydatabse';
$query_items  = mysqli_query($con,$queryitems);
while($row = mysqli_fetch_array($query_items)) { 
    $lines[] = [
        "Description"=> "Loop Description", 
        "DetailType"=> "SalesItemLineDetail", 
        "SalesItemLineDetail"=> [
            "TaxCodeRef"=> [
                "value"=> "TAX"
            ], 
            "Qty"=> 1, 
            "UnitPrice"=> 200, 
            "ItemRef"=> [
                "name"=> "Loop Name", 
                "value"=> "5"
            ]
        ], 
        "LineNum"=> 1, 
        "Amount"=> 200.00, 
        "Id"=> "1"
    ];
}

$invoice['Line'] = $lines;

$theResourceObj = Invoice::create($invoice);


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x