gpt4 book ai didi

mysql - 需要迭代数组以捕获所有行 - 目前仅保存 [0] 或第一条记录中的数字

转载 作者:行者123 更新时间:2023-11-29 09:34:25 25 4
gpt4 key购买 nike

我需要一些帮助来存储数组。下面定义的流程正在运行并保存记录!它保存[0]列中定义的记录。如果存在 0,则保存记录 1,如果存在 1,则保存记录 2,依此类推。

现在我需要自动化此操作,以便它在迭代时对每个记录执行此操作。也许第二个 foreach 语句将它们联系在一起?或者带有整数变量的 for 循环?我尝试了很多组合,但仍然不起作用。

//0 = feeobject row[]: to keyfield=>val
//Array ([0] => 0)

foreach($AgencyFeesBasicArray['AgencyFeesGetInfoResult']['FeeObject'][0] as $key=>$data ) {


$PaymentID = $AgencyFeesBasicArray['AgencyFeesGetInfoResult']['FeeObject'][0]['PaymentID'];
$ClientID = $AgencyFeesBasicArray['AgencyFeesGetInfoResult']['FeeObject'][0]['ClientID'];
$ClientName = $AgencyFeesBasicArray['AgencyFeesGetInfoResult']['FeeObject'][0]['ClientName'];
$Account_ID = $AgencyFeesBasicArray['AgencyFeesGetInfoResult']['FeeObject'][0]['Account_ID'];
$State = $AgencyFeesBasicArray['AgencyFeesGetInfoResult']['FeeObject'][0]['State'];
$PaymentDate = $AgencyFeesBasicArray['AgencyFeesGetInfoResult']['FeeObject'][0]['PaymentDate'];
$Amount = $AgencyFeesBasicArray['AgencyFeesGetInfoResult']['FeeObject'][0]['Amount'];
$CheckID = $AgencyFeesBasicArray['AgencyFeesGetInfoResult']['FeeObject'][0]['CheckID'];
$CreditorName = $AgencyFeesBasicArray['AgencyFeesGetInfoResult']['FeeObject'][0]['CreditorName'];
$DRC_ClientID = $AgencyFeesBasicArray['AgencyFeesGetInfoResult']['FeeObject'][0]['DRC_ClientID'];
$DRC_TransactionID = $AgencyFeesBasicArray['AgencyFeesGetInfoResult']['FeeObject'][0]['DRC_TransactionID'];

$sql = "INSERT INTO tblAgencyFees (PaymentID, ClientID, ClientName, Account_ID, State, PaymentDate, Amount, CheckID, CreditorName, DRC_ClientID, DRC_TransactionID) VALUES ('".$PaymentID."', '".$ClientID."', '".$ClientName."', '".$Account_ID."', '".$State."', '".$PaymentDate."', '".$Amount."', '".$CheckID."', '".$CreditorName."', '".$DRC_ClientID."', '".$DRC_TransactionID."')";
mysqli_query($connection, $sql);
}
//}
//}
echo $sql;

$res = mysqli_query($connection, $sql);
If( !$res ) exit( mysqli_error($connection) );

数组:

Array ( 
[AgencyFeesGetInfoResult] => Array (
[FeeObject] => Array (
[0] => Array (
[PaymentID] => 816
[ClientID] => 1141
[ClientName] => Ortega, Daniel
[Account_ID] => 2222100000010717
[State] => OK
[PaymentDate] => 2019-07-31T00:00:00
[Amount] => 8.0000
[CheckID] => 10
[CreditorName] => 0
[DRC_ClientID] => 1195
[DRC_TransactionID] =>
)
[1] => Array (
[PaymentID] => 817
[ClientID] => 1141
[ClientName] => Ortega, Daniel
[Account_ID] => 2222100000010717
[State] => OK
[PaymentDate] => 2019-07-31T00:00:00
[Amount] => 92.0000
[CheckID] => 11
[CreditorName] => MF
[DRC_ClientID] => 1195
[DRC_TransactionID] =>
)
[2] => Array (
[PaymentID] => 847
[ClientID] => 1141
[ClientName] => Ortega, Daniel
[Account_ID] => 2222100000010717
[State] => OK
[PaymentDate] => 2019-08-14T13:21:49.23
[Amount] => 195.0000
[CheckID] => 13
[CreditorName] => MF
[DRC_ClientID] => 1195
[DRC_TransactionID] =>
)
)
)
)

最佳答案

您可以对数据进行简单的循环并进行多次插入。

$arrFeeObjects = $AgencyFeesBasicArray['AgencyFeesGetInfoResult']['FeeObject'];

if(count($arrFeeObjects) > 0)
{
foreach($arrFeeObjects as $intKey => $data)
{
$sql = "INSERT INTO tblAgencyFees (PaymentID, ClientID, ClientName, Account_ID, State, PaymentDate, Amount, CheckID, CreditorName, DRC_ClientID, DRC_TransactionID)
VALUES ('". $data['PaymentID'] ."', '". $data['ClientID'] ."', '". $data['ClientName'] ."', '". $data['Account_ID'] ."', '". $data['State'] ."', '". $data['PaymentDate'] ."', '". $data['Amount'] ."', '". $data['CheckID'] ."', '". $data['CreditorName'] ."', '". $data['DRC_ClientID'] ."', '". $data['DRC_TransactionID'] ."')";

mysqli_query($connection, $sql);
}
}

关于mysql - 需要迭代数组以捕获所有行 - 目前仅保存 [0] 或第一条记录中的数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57978139/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com