MySQL Forums
Forum List  »  PHP

php array saving only one record
Posted by: David Koehne
Date: September 09, 2019 12:13PM

I have the following array called $AgencyFeesBasicArray:

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] => ) ) ) )

It was brought over as stdClass and then converted to what is above with json below:

$AgencyFeesBasicArray = json_decode(json_encode($soapResult), true);
print_r($AgencyFeesBasicArray);

This recursive iterator returns the keys to values shown below:

$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($AgencyFeesBasicArray));
foreach($iterator as $key => $value) {
echo "$key => $value\n";echo '<br>';
}

returns:
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 =>
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 =>
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 =>

… and that's great! Those are the values to be inserted for the three records.

THE PROBLEM I AM HAVING IS THAT THE FOREACH STATEMENT IS ONLY INSERTING THE FIRST RECORD (ROW 1) TO THE TABLE BUT NOT THE OTHERS.

Here is the code:

$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($AgencyFeesBasicArray));

foreach ($iterator as $key => $value) {

$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);
}

Options: ReplyQuote


Subject
Written By
Posted
php array saving only one record
September 09, 2019 12:13PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.