Ingus Graholskis Ingus Graholskis - 1 month ago 6
PHP Question

multidimensional array gives out only 1 record

I have this code that takes out data from Xml file.

My problem is that it only takes out first record from array and i cant find whats wrong ? I m pretty bad at multidimensional array :(

and just to you know yes there is total 3 records for this person but it returns only 1 record in this case.

$responseXml = substr($contents, strpos($contents, "\r\n\r\n")+4);

$responseObject = \Parsers\XML2ObjectParser::parseXmlText($responseXml, new \CBResponse\GetReportResultClass());

if($responseObject->resultCode==1){
$array = array();
$array = xml2array(str_replace("
","",base64_decode($responseObject->reportContent)));
}


deleteAllRows("list", " WHERE PersonCode = '$pk'");
deleteAllRows("records", " WHERE PersonCode = '$pk'");

$c_lial=count($array['cb:Report']['Debts']['LiabilityDebts']['LiabilityType']);


if ($c_lial==1){

$type=$information=null;
if (isset($array['cb:Report']['Debts']['LiabilityDebts']['LiabilityType'])){

$type='text';

$information.='text: '.$array['cb:Report']['Debts']['LiabilityDebts']['LiabilityType'].'<br/>';

if (count($array['cb:Report']['Debts']['LiabilityDebts']['Debt']['DebtDate'])==1){

$LiabilityDebts='y';

$information.='text: '.$array['cb:Report']['Debts']['LiabilityDebts']['Debt']['DebtDate'].'<br/>';

if ($array['cb:Report']['Debts']['LiabilityDebts']['Debt']['Sum']['Code']=='1'){
$information.='text: '.sprintf('%0.2f',$array['cb:Report']['Debts']['LiabilityDebts']['Debt']['Sum']['Total']).'<br/>';
}
if ($array['cb:Report']['Debts']['LiabilityDebts']['Debt']['Sum']['Code']=='2'){
$information.= 'text: '.$array['cb:Report']['Debts']['LiabilityDebts']['Debt']['Sum']['Total'].'<br/>';
$information.= 'text: '.sprintf('%0.2f',$array['cb:Report']['Debts']['LiabilityDebts']['Debt']['Sum']['Paid']).'<br/>';
}
if (isset($array['cb:Report']['Debts']['LiabilityDebts']['Debt']['Termination'])){
$information.= 'text: '. $array['cb:Report']['Debts']['LiabilityDebts']['Debt']['Termination'].'<br/>';
}
if (isset($array['cb:Report']['Debts']['LiabilityDebts']['Debt']['InclusionDate'])){
$information.= 'text: '. $array['cb:Report']['Debts']['LiabilityDebts']['Debt']['InclusionDate'].'<br/>';
}
if (isset($array['cb:Report']['Debts']['LiabilityDebts']['Debt']['LastUpdateDate'])){
$information.= 'text: '. $array['cb:Report']['Debts']['LiabilityDebts']['Debt']['LastUpdateDate'].'<br/><br/>';
}
}

if (count($array['cb:Report']['Debts']['LiabilityDebts']['Debt']['DebtDate'])>1){

foreach ($array['cb:Report']['Debts']['LiabilityDebts']['Debt'] AS $Debt){
$LiabilityDebts='y';

if (isset($Debt['DebtDate'])){
$information.='text: '.$Debt['DebtDate'].'<br/>';


foreach ($Debt['Sum'] AS $Sum){

if ($Sum['Code']=='1'){
$information.='text: '.sprintf('%0.2f',$Sum['Total']).'<br/>';
}
if ($Sum['Code']=='2'){
$information.= 'text: '.$Sum['Total'].'<br/>';
$information.= 'text: '.sprintf('%0.2f',$Sum['Paid']).'<br/>';
}
}

if (isset($Debt['Termination'])){
$information.= 'text: '. $Debt['Termination'].'<br/>';
}
if (isset($Debt['InclusionDate'])){
$information.= 'text: '. $Debt['InclusionDate'].'<br/>';
}
if (isset($Debt['LastUpdateDate'])){
$information.= 'text: '. $Debt['LastUpdateDate'].'<br/><br/>';
}
}
}
}

$information = str_replace('T00:00:00','',$information);
$form_data = array(
'type' => $type,
'information' => $information,
'PersonCode' => $array['cb:Report']['IdentificationCode'],
'createdBy' => $id
);

insertNewRows("list", $form_data);
}
}else{
$type=$information=null;

if (isset($array['cb:Report']['Debts']['LiabilityDebts']['LiabilityType'])){
foreach ($array['cb:Report']['Debts']['LiabilityDebts'] AS $LiabilityDebt){

if (isset($LiabilityDebt['LiabilityType'])){

$type='text';

$information.='text: '.$LiabilityDebt['LiabilityType'].'<br/>';
$information.='text: '.$LiabilityDebt['LiabilityDate'].'<br/>';
$information.='text: '.$LiabilityDebt['Nace'].'<br/>';

if (count($LiabilityDebt['Debt']['DebtDate'])==1){
$LiabilityDebts='y';

$information.='text: '.$LiabilityDebt['Debt']['DebtDate'].'<br/>';

if ($LiabilityDebt['Debt']['Sum']['Code']=='1'){
$information.='text: '.sprintf('%0.2f',$LiabilityDebt['Debt']['Sum']['Total']).'<br/>';
}
if ($LiabilityDebt['Debt']['Sum']['Code']=='2'){
$information.= 'text: '.sprintf('%0.2f',$LiabilityDebt['Debt']['Sum']['Total']).'<br/>';
$information.= 'text: '.sprintf('%0.2f',$LiabilityDebt['Debt']['Sum']['Paid']).'<br/>';
}

if (isset($LiabilityDebt['Debt']['Termination'])){
$information.= 'text: '. $LiabilityDebt['Debt']['Termination'].'<br/>';
}
if (isset($LiabilityDebt['Debt']['InclusionDate'])){
$information.= 'text: '. $LiabilityDebt['Debt']['InclusionDate'].'<br/>';
}
if (isset($LiabilityDebt['Debt']['LastUpdateDate'])){
$information.= 'text: '. $LiabilityDebt['Debt']['LastUpdateDate'].'<br/><br/>';
}

}
if (count($LiabilityDebt['Debt']['DebtDate'])>1){

foreach ($LiabilityDebt['Debt'] AS $Debt){
$LiabilityDebts='y';

if (isset($Debt['DebtDate'])){
$information.='text: '.$Debt['DebtDate'].'<br/>';

foreach ($Debt['Sum'] AS $Sum){

if ($Sum['Code']=='1'){
$information.='text: '.sprintf('%0.2f',$Sum['Total']).'<br/>';
}
if ($Sum['Code']=='2'){
$information.= 'text: '.sprintf('%0.2f',$Sum['Total']).'<br/>';
$information.= 'text: '.sprintf('%0.2f',$Sum['Paid']).'<br/>';
}
}
if (isset($Debt['Termination'])){
$information.= 'text: '. $Debt['Termination'].'<br/>';
}
if (isset($Debt['InclusionDate'])){
$information.= 'text: '. $Debt['InclusionDate'].'<br/>';
}
if (isset($Debt['LastUpdateDate'])){
$information.= 'text: '. $Debt['LastUpdateDate'].'<br/><br/>';
}
}
}
}
}

}
$information = str_replace('T00:00:00','',$information);
$form_data = array(
'type' => $type,
'information' => $information,
'PersonCode' => $array['cb:Report']['IdentificationCode'],
'createdBy' => $id
);

insertNewRows("list", $form_data);
}

}


Note : This is not full code as i think this part is the one doing it wrong!As long as for other parts result was good! Please help Thanks

Answer

I added [0] in few places and made some changes in rest code and got it working.

Comments