Skip to content
Advertisement

How do I make the JSON API CURL data into a normal print on what all info i need?

I dont know if you understood my question.

This is the JSON:

{
  "data":{
     "awbNo":"7812422306921",
     "carrierName":"FEDEX",
     "allData":{
        "id":5695945,
        "awbNo":"7812422306921",
        "childAwbID":null,
        "returnOrReverse":null,
        "expectedDeliveryDate":"2020-12-19T14:30:00.000Z",
        "updated":"2020-12-13T06:06:44.000Z",
        "carrierName":"FEDEX",
        "cancelled":false
     },
     "events":[
        {
           "status":"IT",
           "Remarks":"In transit",
           "Location":"CHENNAI",
           "Time":"2020-12-12T21:38:00.000Z"
        },
        {
           "status":"IT",
           "Remarks":"In transit",
           "Location":"CHENNAI",
           "Time":"2020-12-12T20:41:00.000Z"
        },
        {
           "status":"IT",
           "Remarks":"Left FedEx origin facility",
           "Location":"PONDICHERRY",
           "Time":"2020-12-12T15:31:00.000Z"
        },
        {
           "status":"IT",
           "Remarks":"In transit",
           "Location":"PONDICHERRY",
           "Time":"2020-12-12T15:31:00.000Z"
        },
        {
           "status":"PU",
           "Remarks":"Picked up",
           "Location":"PONDICHERRY",
           "Time":"2020-12-12T11:24:00.000Z"
        },
        {
           "status":"SB",
           "Remarks":"Shipment information sent to FedEx",
           "Location":null,
           "Time":"2020-12-11T12:19:11.000Z"
        }
     ]
  }
}

I used:

<?php
foreach ( $data['data'] as  $row )
{
    ?>
    <tr>
        
        <td><?php echo $row['awbNo']; ?></td><br>
        <td><?php echo $row['events']; ?></td>
        
    </tr>
    <?php
}
?>

i dont get the events i get only the awbNo. WHat to do to get the events?

Advertisement

Answer

On your json data events is definning as a array.You should to define the values with your events data.

<?php
foreach ( $data['data'] as  $row ){
?>
<tr>
    
    <td><?php echo $row['awbNo']; ?></td><br>
    <td><?php echo $row['events']['status']; ?></td>
    
</tr>
<?php
}
?>
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement