mysql 循环问题

Issue with mysql loop

Intuit 集成。 与创建发票。我需要在创建发票时从循环中获取项目。

我也尝试过先创建循环并在发票创建中使用 $items,但也出现错误。 “格式错误。需要数组或对象的元素。”

不喜欢我的循环。我怎样才能做到这一点 ?

$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" => "email@somewhere.com"
    ]
]);

你不能在数组文字中放置循环。

Invoice::create().

调用之外逐步构建数组
$invoice = [
    "TotalAmt" => 200.00,
    "CustomerRef"=> [
        "value"=> 1
    ],
    "BillEmail" => [
        "Address" => "email@somewhere.com"
    ]
];
$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);