Jump to content

JSON Api results, loop through array and extract records to html table


gyesdahl
Go to solution Solved by Barand,

Recommended Posts

Hi,I am new to json api calls and am learning as I go... With his particular issue I am not able to find anything that can help me after searching for days on end to find something simiular I can gleen info from.

I have done an API call to get flight routing. I have results returned and have it decoded as follows.

//$json = json_encode($requests_response->getData($id));
$requests_response = Requests::get($url, $headers);
$response_body = json_decode($requests_response->body);

$objects =json_decode($requests_response->body,TRUE);

I have then retrieved for viewing the contents as follows producing the results in onbe array (associative array?):

print_r($objects['data']);
echo '<br><br>';

the print_r results

Array ( [0] => Array ( [type] => flight-offer [id] => 1 [source] => GDS [instantTicketingRequired] => [nonHomogeneous] => [oneWay] => [lastTicketingDate] => 2023-03-01 [numberOfBookableSeats] => 7 [itineraries] => Array ( [0] => Array ( [duration] => PT18H50M [segments] => Array ( [0] => Array ( [departure] => Array ( [iataCode] => CPT [at] => 2023-03-01T12:55:00 ) [arrival] => Array ( [iataCode] => DOH [at] => 2023-03-01T23:40:00 ) [carrierCode] => QR [number] => 1372 [aircraft] => Array ( [code] => 77W ) [operating] => Array ( [carrierCode] => QR ) [duration] => PT9H45M [id] => 5 [numberOfStops] => 0 [blacklistedInEU] => ) [1] => Array ( [departure] => Array ( [iataCode] => DOH [at] => 2023-03-02T01:15:00 ) [arrival] => Array ( [iataCode] => LGW [terminal] => S [at] => 2023-03-02T05:45:00 ) [carrierCode] => QR [number] => 5943 [aircraft] => Array ( [code] => 777 ) [operating] => Array ( [carrierCode] => BA ) [duration] => PT7H30M [id] => 6 [numberOfStops] => 0 [blacklistedInEU] => ) ) ) [1] => Array ( [duration] => PT19H10M [segments] => Array ( [0] => Array ( [departure] => Array ( [iataCode] => LGW [terminal] => S [at] => 2023-03-08T14:05:00 ) [arrival] => Array ( [iataCode] => DOH [at] => 2023-03-08T23:45:00 ) [carrierCode] => QR [number] => 5942 [aircraft] => Array ( [code] => 777 ) [operating] => Array ( [carrierCode] => BA ) [duration] => PT6H40M [id] => 7 [numberOfStops] => 0 [blacklistedInEU] => ) [1] => Array ( [departure] => Array ( [iataCode] => DOH [at] => 2023-03-09T02:15:00 ) [arrival] => Array ( [iataCode] => CPT [at] => 2023-03-09T11:15:00 ) [carrierCode] => QR [number] => 1369 [aircraft] => Array ( [code] => 77W ) [operating] => Array ( [carrierCode] => QR ) [duration] => PT10H [id] => 8 [numberOfStops] => 0 [blacklistedInEU] => ) ) ) ) [price] => Array ( [currency] => ZAR [total] => 12632.45 [base] => 6370.00 [fees] => Array ( [0] => Array ( [amount] => 0.00 [type] => SUPPLIER ) [1] => Array ( [amount] => 0.00 [type] => TICKETING ) ) [grandTotal] => 12632.45 ) [pricingOptions] => Array ( [fareType] => Array ( [0] => PUBLISHED ) [includedCheckedBagsOnly] => 1 ) [validatingAirlineCodes] => Array ( [0] => QR ) [travelerPricings] => Array ( [0] => Array ( [travelerId] => 1 [fareOption] => STANDARD [travelerType] => ADULT [price] => Array ( [currency] => ZAR [total] => 12632.45 [base] => 6370.00 ) [fareDetailsBySegment] => Array ( [0] => Array ( [segmentId] => 5 [cabin] => ECONOMY [fareBasis] => NLR1R1RX [brandedFare] => ECLASSIC [class] => N [includedCheckedBags] => Array ( [quantity] => 2 ) ) [1] => Array ( [segmentId] => 6 [cabin] => ECONOMY [fareBasis] => NLR1R1RX [brandedFare] => ECLASSIC [class] => N [includedCheckedBags] => Array ( [quantity] => 2 ) ) [2] => Array ( [segmentId] => 7 [cabin] => ECONOMY [fareBasis] => NLR1R1RX [brandedFare] => ECLASSIC [class] => N [includedCheckedBags] => Array ( [quantity] => 2 ) ) [3] => Array ( [segmentId] => 8 [cabin] => ECONOMY [fareBasis] => NLR1R1RX [brandedFare] => ECLASSIC [class] => N [includedCheckedBags] => Array ( [quantity] => 2 ) ) ) ) ) ) [1] => Array ( [type] => flight-offer [id] => 2 [source] => GDS [instantTicketingRequired] => [nonHomogeneous] => [oneWay] => [lastTicketingDate] => 2023-03-01 [numberOfBookableSeats] => 7 [itineraries] => Array ( [0] => Array ( [duration] => PT19H15M [segments] => Array ( [0] => Array ( [departure] => Array ( [iataCode] => CPT [at] => 2023-03-01T19:10:00 ) [arrival] => Array ( [iataCode] => DOH [at] => 2023-03-02T05:55:00 ) [carrierCode] => QR [number] => 1370 [aircraft] => Array ( [code] => 77W ) [operating] => Array ( [carrierCode] => QR ) [duration] => PT9H45M [id] => 1 [numberOfStops] => 0 [blacklistedInEU] => ) [1] => Array ( [departure] => Array ( [iataCode] => DOH [at] => 2023-03-02T08:05:00 ) [arrival] => Array ( [iataCode] => LGW [terminal] => N [at] => 2023-03-02T12:25:00 ) [carrierCode] => QR [number] => 327 [aircraft] => Array ( [code] => 788 ) [operating] => Array ( [carrierCode] => QR ) [duration] => PT7H20M [id] => 2 [numberOfStops] => 0 [blacklistedInEU] => ) ) ) [1] => Array ( [duration] => PT19H10M [segments] => Array ( [0] => Array ( [departure] => Array ( [iataCode] => LGW [terminal] => S [at] => 2023-03-08T14:05:00 ) [arrival] => Array ( [iataCode] => DOH [at] => 2023-03-08T23:45:00 ) [carrierCode] => QR [number] => 5942 [aircraft] => Array ( [code] => 777 ) [operating] => Array ( [carrierCode] => BA ) [duration] => PT6H40M [id] => 7 [numberOfStops] => 0 [blacklistedInEU] => ) [1] => Array ( [departure] => Array ( [iataCode] => DOH [at] => 2023-03-09T02:15:00 ) [arrival] => Array ( [iataCode] => CPT [at] => 2023-03-09T11:15:00 ) [carrierCode] => QR [number] => 1369 [aircraft] => Array ( [code] => 77W ) [operating] => Array ( [carrierCode] => QR ) [duration] => PT10H [id] => 8 [numberOfStops] => 0 [blacklistedInEU] => ) ) ) ) [price] => Array ( [currency] => ZAR [total] => 12632.45 [base] => 6370.00 [fees] => Array ( [0] => Array ( [amount] => 0.00 [type] => SUPPLIER ) [1] => Array ( [amount] => 0.00 [type] => TICKETING ) ) [grandTotal] => 12632.45 ) [pricingOptions] => Array ( [fareType] => Array ( [0] => PUBLISHED ) [includedCheckedBagsOnly] => 1 ) [validatingAirlineCodes] => Array ( [0] => QR ) [travelerPricings] => Array ( [0] => Array ( [travelerId] => 1 [fareOption] => STANDARD [travelerType] => ADULT [price] => Array ( [currency] => ZAR [total] => 12632.45 [base] => 6370.00 ) [fareDetailsBySegment] => Array ( [0] => Array ( [segmentId] => 1 [cabin] => ECONOMY [fareBasis] => NLR1R1RX [brandedFare] => ECLASSIC [class] => N [includedCheckedBags] => Array ( [quantity] => 2 ) ) [1] => Array ( [segmentId] => 2 [cabin] => ECONOMY [fareBasis] => NLR1R1RX [brandedFare] => ECLASSIC [class] => N [includedCheckedBags] => Array ( [quantity] => 2 ) ) [2] => Array ( [segmentId] => 7 [cabin] => ECONOMY [fareBasis] => NLR1R1RX [brandedFare] => ECLASSIC [class] => N [includedCheckedBags] => Array ( [quantity] => 2 ) ) [3] => Array ( [segmentId] => 8 [cabin] => ECONOMY [fareBasis] => NLR1R1RX [brandedFare] => ECLASSIC [class] => N [includedCheckedBags] => Array ( [quantity] => 2 ) ) ) ) ) ) [2] => Array ( [type] => flight-offer [id] => 3 [source] => GDS [instantTicketingRequired] => [nonHomogeneous] => [oneWay] => [lastTicketingDate] => 2023-03-01 [numberOfBookableSeats] => 7 [itineraries] => Array ( [0] => Array ( [duration] => PT25H30M [segments] => Array ( [0] => Array ( [departure] => Array ( [iataCode] => CPT [at] => 2023-03-01T12:55:00 ) [arrival] => Array ( [iataCode] => DOH [at] => 2023-03-01T23:40:00 ) [carrierCode] => QR [number] => 1372 [aircraft] => Array ( [code] => 77W ) [operating] => Array ( [carrierCode] => QR ) [duration] => PT9H45M [id] => 3 [numberOfStops] => 0 [blacklistedInEU] => ) [1] => Array ( [departure] => Array ( [iataCode] => DOH [at] => 2023-03-02T08:05:00 ) [arrival] => Array ( [iataCode] => LGW [terminal] => N [at] => 2023-03-02T12:25:00 ) [carrierCode] => QR [number] => 327 [aircraft] => Array ( [code] => 788 ) [operating] => Array ( [carrierCode] => QR ) [duration] => PT7H20M [id] => 4 [numberOfStops] => 0 [blacklistedInEU] => ) ) ) [1] => Array ( [duration] => PT19H10M [segments] => Array ( [0] => Array ( [departure] => Array ( [iataCode] => LGW [terminal] => S [at] => 2023-03-08T14:05:00 ) [arrival] => Array ( [iataCode] => DOH [at] => 2023-03-08T23:45:00 ) [carrierCode] => QR [number] => 5942 [aircraft] => Array ( [code] => 777 ) [operating] => Array ( [carrierCode] => BA ) [duration] => PT6H40M [id] => 7 [numberOfStops] => 0 [blacklistedInEU] => ) [1] => Array ( [departure] => Array ( [iataCode] => DOH [at] => 2023-03-09T02:15:00 ) [arrival] => Array ( [iataCode] => CPT [at] => 2023-03-09T11:15:00 ) [carrierCode] => QR [number] => 1369 [aircraft] => Array ( [code] => 77W ) [operating] => Array ( [carrierCode] => QR ) [duration] => PT10H [id] => 8 [numberOfStops] => 0 [blacklistedInEU] => ) ) ) ) [price] => Array ( [currency] => ZAR [total] => 12632.45 [base] => 6370.00 [fees] => Array ( [0] => Array ( [amount] => 0.00 [type] => SUPPLIER ) [1] => Array ( [amount] => 0.00 [type] => TICKETING ) ) [grandTotal] => 12632.45 ) [pricingOptions] => Array ( [fareType] => Array ( [0] => PUBLISHED ) [includedCheckedBagsOnly] => 1 ) [validatingAirlineCodes] => Array ( [0] => QR ) [travelerPricings] => Array ( [0] => Array ( [travelerId] => 1 [fareOption] => STANDARD [travelerType] => ADULT [price] => Array ( [currency] => ZAR [total] => 12632.45 [base] => 6370.00 ) [fareDetailsBySegment] => Array ( [0] => Array ( [segmentId] => 3 [cabin] => ECONOMY [fareBasis] => NLR1R1RX [brandedFare] => ECLASSIC [class] => N [includedCheckedBags] => Array ( [quantity] => 2 ) ) [1] => Array ( [segmentId] => 4 [cabin] => ECONOMY [fareBasis] => NLR1R1RX [brandedFare] => ECLASSIC [class] => N [includedCheckedBags] => Array ( [quantity] => 2 ) ) [2] => Array ( [segmentId] => 7 [cabin] => ECONOMY [fareBasis] => NLR1R1RX [brandedFare] => ECLASSIC [class] => N [includedCheckedBags] => Array ( [quantity] => 2 ) ) [3] => Array ( [segmentId] => 8 [cabin] => ECONOMY [fareBasis] => NLR1R1RX [brandedFare] => ECLASSIC [class] => N [includedCheckedBags] => Array ( [quantity] => 2 ) ) ) ) ) ) [3] => Array ( [type] => flight-offer [id] => 4 [source] => GDS [instantTicketingRequired] => [nonHomogeneous] => [oneWay] => [lastTicketingDate] => 2023-03-01 [numberOfBookableSeats] => 7 [itineraries] => Array ( [0] => Array ( [duration] => PT18H50M [segments] => Array ( [0] => Array ( [departure] => Array ( [iataCode] => CPT [at] => 2023-03-01T12:55:00 ) [arrival] => Array ( [iataCode] => DOH [at] => 2023-03-01T23:40:00 ) [carrierCode] => QR [number] => 1372 [aircraft] => Array ( [code] => 77W ) [operating] => Array ( [carrierCode] => QR ) [duration] => PT9H45M [id] => 5 [numberOfStops] => 0 [blacklistedInEU] => ) [1] => Array ( [departure] => Array ( [iataCode] => DOH [at] => 2023-03-02T01:15:00 ) [arrival] => Array ( [iataCode] => LGW [terminal] => S [at] => 2023-03-02T05:45:00 ) [carrierCode] => QR [number] => 5943 [aircraft] => Array ( [code] => 777 ) [operating] => Array ( [carrierCode] => BA ) [duration] => PT7H30M [id] => 6 [numberOfStops] => 0 [blacklistedInEU] => ) ) ) [1] => Array ( [duration] => PT19H10M [segments] => Array ( [0] => Array ( [departure] => Array ( [iataCode] => LGW [terminal] => N [at] => 2023-03-08T14:05:00 ) [arrival] => Array ( [iataCode] => DOH [at] => 2023-03-08T23:50:00 ) [carrierCode] => QR [number] => 328 [aircraft] => Array ( [code] => 788 ) [operating] => Array ( [carrierCode] => QR ) [duration] => PT6H45M [id] => 9 [numberOfStops] => 0 [blacklistedInEU] => ) [1] => Array ( [departure] => Array ( [iataCode] => DOH [at] => 2023-03-09T02:15:00 ) [arrival] => Array ( [iataCode] => CPT [at] => 2023-03-09T11:15:00 ) [carrierCode] => QR [number] => 1369 [aircraft] => Array ( [code] => 77W ) [operating] => Array ( [carrierCode] => QR ) [duration] => PT10H [id] => 10 [numberOfStops] => 0 [blacklistedInEU] => ) ) ) ) [price] => Array ( [currency] => ZAR [total] => 12670.45 [base] => 6370.00 [fees] => Array ( [0] => Array ( [amount] => 0.00 [type] => SUPPLIER ) [1] => Array ( [amount] => 0.00 [type] => TICKETING ) ) [grandTotal] => 12670.45 ) [pricingOptions] => Array ( [fareType] => Array ( [0] => PUBLISHED ) [includedCheckedBagsOnly] => 1 ) [validatingAirlineCodes] => Array ( [0] => QR ) [travelerPricings] => Array ( [0] => Array ( [travelerId] => 1 [fareOption] => STANDARD [travelerType] => ADULT [price] => Array ( [currency] => ZAR [total] => 12670.45 [base] => 6370.00 ) [fareDetailsBySegment] => Array ( [0] => Array ( [segmentId] => 5 [cabin] => ECONOMY [fareBasis] => NLR1R1RX [brandedFare] => ECLASSIC [class] => N [includedCheckedBags] => Array ( [quantity] => 2 ) ) [1] => Array ( [segmentId] => 6 [cabin] => ECONOMY [fareBasis] => NLR1R1RX [brandedFare] => ECLASSIC [class] => N [includedCheckedBags] => Array ( [quantity] => 2 ) ) [2] => Array ( [segmentId] => 9 [cabin] => ECONOMY [fareBasis] => NLR1R1RX [brandedFare] => ECLASSIC [class] => N [includedCheckedBags] => Array ( [quantity] => 2 ) ) [3] => Array ( [segmentId] => 10 [cabin] => ECONOMY [fareBasis] => NLR1R1RX [brandedFare] => ECLASSIC [class] => N [includedCheckedBags] => Array ( [quantity] => 2 ) ) ) ) ) ) [4] => Array ( [type] => flight-offer [id] => 5 [source] => GDS [instantTicketingRequired] => [nonHomogeneous] => [oneWay] => [lastTicketingDate] => 2023-03-01 [numberOfBookableSeats] => 9 [itineraries] => Array ( [0] => Array ( [duration] => PT19H15M [segments] => Array ( [0] => Array ( [departure] => Array ( [iataCode] => CPT [at] => 2023-03-01T19:10:00 ) [arrival] => Array ( [iataCode] => DOH [at] => 2023-03-02T05:55:00 ) [carrierCode] => QR [number] => 1370 [aircraft] => Array ( [code] => 77W ) [operating] => Array ( [carrierCode] => QR ) [duration] => PT9H45M [id] => 1 [numberOfStops] => 0 [blacklistedInEU] => ) [1] => Array ( [departure] => Array ( [iataCode] => DOH [at] => 2023-03-02T08:05:00 ) [arrival] => Array ( [iataCode] => LGW [terminal] => N [at] => 2023-03-02T12:25:00 ) [carrierCode] => QR [number] => 327 [aircraft] => Array ( [code] => 788 ) [operating] => Array ( [carrierCode] => QR ) [duration] => PT7H20M [id] => 2 [numberOfStops] => 0 [blacklistedInEU] => ) ) ) [1] => Array ( [duration] => PT19H10M [segments] => Array ( [0] => Array ( [departure] => Array ( [iataCode] => LGW [terminal] => N [at] => 2023-03-08T14:05:00 ) [arrival] => Array ( [iataCode] => DOH [at] => 2023-03-08T23:50:00 ) [carrierCode] => QR [number] => 328 [aircraft] => Array ( [code] => 788 ) [operating] => Array ( [carrierCode] => QR ) [duration] => PT6H45M [id] => 9 [numberOfStops] => 0 [blacklistedInEU] => ) [1] => Array ( [departure] => Array ( [iataCode] => DOH [at] => 2023-03-09T02:15:00 ) [arrival] => Array ( [iataCode] => CPT [at] => 2023-03-09T11:15:00 ) [carrierCode] => QR [number] => 1369 [aircraft] => Array ( [code] => 77W ) [operating] => Array ( [carrierCode] => QR ) [duration] => PT10H [id] => 10 [numberOfStops] => 0 [blacklistedInEU] => ) ) ) ) [price] => Array ( [currency] => ZAR [total] => 12670.45 [base] => 6370.00 [fees] => Array ( [0] => Array ( [amount] => 0.00 [type] => SUPPLIER ) [1] => Array ( [amount] => 0.00 [type] => TICKETING ) ) [grandTotal] => 12670.45 ) [pricingOptions] => Array ( [fareType] => Array ( [0] => PUBLISHED ) [includedCheckedBagsOnly] => 1 ) [validatingAirlineCodes] => Array ( [0] => QR ) [travelerPricings] => Array ( [0] => Array ( [travelerId] => 1 [fareOption] => STANDARD [travelerType] => ADULT [price] => Array ( [currency] => ZAR [total] => 12670.45 [base] => 6370.00 ) [fareDetailsBySegment] => Array ( [0] => Array ( [segmentId] => 1 [cabin] => ECONOMY [fareBasis] => NLR1R1RX [brandedFare] => ECLASSIC [class] => N [includedCheckedBags] => Array ( [quantity] => 2 ) ) [1] => Array ( [segmentId] => 2 [cabin] => ECONOMY [fareBasis] => NLR1R1RX [brandedFare] => ECLASSIC [class] => N [includedCheckedBags] => Array ( [quantity] => 2 ) ) [2] => Array ( [segmentId] => 9 [cabin] => ECONOMY [fareBasis] => NLR1R1RX [brandedFare] => ECLASSIC [class] => N [includedCheckedBags] => Array ( [quantity] => 2 ) ) [3] => Array ( [segmentId] => 10 [cabin] => ECONOMY [fareBasis] => NLR1R1RX [brandedFare] => ECLASSIC [class] => N [includedCheckedBags] => Array ( [quantity] => 2 ) ) ) ) ) ) ) 

Within the array are r details  for 5 flights (each API call will have variable amounts of flights) , containing details of each offer identified by a flight-offer [id]. It appears there are arrays within arrays and I am well, just going no-where. I have tried various for each loops over the past few days  without any success and am now back to square on e....

I need to get data into an html table as follows

<table width="50%" border="1" align="center">	<tr>
    <td><div align="center"><b>Offer id :</b></div></td>
    <td><div align="center"><b>Source :</b> GDS</div></td>
     <td style="font-weight: bold;"><div align="center">Total price :</div></td>
     </td>
       <div align="center"></div>
     <tr>
     <td><div align="center"><b>Segment</b></div></td>
     <td><div align="center"><b>Flight number</b></div></td>
     <td><div align="center"><b>Departure Time</b></div></td>
     <td><div align="center"><b>Arrival Time</b></div></td>
     </tr>
	 <?PHP
     FOREACH record echo data
	 ?> 
     </table>

For now I only want to extract only those items per record so it produces  the table as in the image below.

I would really be grateful if someone could help me to reproduce the table that I can study and learn from.

Best regards

 

offer table Capture.JPG

Link to comment
Share on other sites

Hi Barand, many thanks for the reply... I will do so...UH.. :) How would i do that, var_dump? I had tried postman and although I get the results to transfer to my own web page is a mission for me.,. I  have exported the scripts but they give far too much for me to get my mind around. But have it in a json file..

 

Edited by gyesdahl
Link to comment
Share on other sites

Hi Barand, Many thanks . I could not echo the statement as you had it as was getting undefined variable errors so I echo the whole $request_response-> body to get the below; Hope it is right..

{"meta":{"count":5,"links":{"self":"https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=CPT&destinationLocationCode=LGW&departureDate=2023-03-01&returnDate=2023-03-08&adults=1&travelClass=ECONOMY¤cyCode=ZAR&max=5"}},"data":[{"type":"flight-offer","id":"1","source":"GDS","instantTicketingRequired":false,"nonHomogeneous":false,"oneWay":false,"lastTicketingDate":"2023-03-01","numberOfBookableSeats":7,"itineraries":[{"duration":"PT18H50M","segments":[{"departure":{"iataCode":"CPT","at":"2023-03-01T12:55:00"},"arrival":{"iataCode":"DOH","at":"2023-03-01T23:40:00"},"carrierCode":"QR","number":"1372","aircraft":{"code":"77W"},"operating":{"carrierCode":"QR"},"duration":"PT9H45M","id":"5","numberOfStops":0,"blacklistedInEU":false},{"departure":{"iataCode":"DOH","at":"2023-03-02T01:15:00"},"arrival":{"iataCode":"LGW","terminal":"S","at":"2023-03-02T05:45:00"},"carrierCode":"QR","number":"5943","aircraft":{"code":"777"},"operating":{"carrierCode":"BA"},"duration":"PT7H30M","id":"6","numberOfStops":0,"blacklistedInEU":false}]},{"duration":"PT19H10M","segments":[{"departure":{"iataCode":"LGW","terminal":"S","at":"2023-03-08T14:05:00"},"arrival":{"iataCode":"DOH","at":"2023-03-08T23:45:00"},"carrierCode":"QR","number":"5942","aircraft":{"code":"777"},"operating":{"carrierCode":"BA"},"duration":"PT6H40M","id":"7","numberOfStops":0,"blacklistedInEU":false},{"departure":{"iataCode":"DOH","at":"2023-03-09T02:15:00"},"arrival":{"iataCode":"CPT","at":"2023-03-09T11:15:00"},"carrierCode":"QR","number":"1369","aircraft":{"code":"77W"},"operating":{"carrierCode":"QR"},"duration":"PT10H","id":"8","numberOfStops":0,"blacklistedInEU":false}]}],"price":{"currency":"ZAR","total":"12632.45","base":"6370.00","fees":[{"amount":"0.00","type":"SUPPLIER"},{"amount":"0.00","type":"TICKETING"}],"grandTotal":"12632.45"},"pricingOptions":{"fareType":["PUBLISHED"],"includedCheckedBagsOnly":true},"validatingAirlineCodes":["QR"],"travelerPricings":[{"travelerId":"1","fareOption":"STANDARD","travelerType":"ADULT","price":{"currency":"ZAR","total":"12632.45","base":"6370.00"},"fareDetailsBySegment":[{"segmentId":"5","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"6","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"7","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"8","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}}]}]},{"type":"flight-offer","id":"2","source":"GDS","instantTicketingRequired":false,"nonHomogeneous":false,"oneWay":false,"lastTicketingDate":"2023-03-01","numberOfBookableSeats":7,"itineraries":[{"duration":"PT19H15M","segments":[{"departure":{"iataCode":"CPT","at":"2023-03-01T19:10:00"},"arrival":{"iataCode":"DOH","at":"2023-03-02T05:55:00"},"carrierCode":"QR","number":"1370","aircraft":{"code":"77W"},"operating":{"carrierCode":"QR"},"duration":"PT9H45M","id":"1","numberOfStops":0,"blacklistedInEU":false},{"departure":{"iataCode":"DOH","at":"2023-03-02T08:05:00"},"arrival":{"iataCode":"LGW","terminal":"N","at":"2023-03-02T12:25:00"},"carrierCode":"QR","number":"327","aircraft":{"code":"788"},"operating":{"carrierCode":"QR"},"duration":"PT7H20M","id":"2","numberOfStops":0,"blacklistedInEU":false}]},{"duration":"PT19H10M","segments":[{"departure":{"iataCode":"LGW","terminal":"S","at":"2023-03-08T14:05:00"},"arrival":{"iataCode":"DOH","at":"2023-03-08T23:45:00"},"carrierCode":"QR","number":"5942","aircraft":{"code":"777"},"operating":{"carrierCode":"BA"},"duration":"PT6H40M","id":"7","numberOfStops":0,"blacklistedInEU":false},{"departure":{"iataCode":"DOH","at":"2023-03-09T02:15:00"},"arrival":{"iataCode":"CPT","at":"2023-03-09T11:15:00"},"carrierCode":"QR","number":"1369","aircraft":{"code":"77W"},"operating":{"carrierCode":"QR"},"duration":"PT10H","id":"8","numberOfStops":0,"blacklistedInEU":false}]}],"price":{"currency":"ZAR","total":"12632.45","base":"6370.00","fees":[{"amount":"0.00","type":"SUPPLIER"},{"amount":"0.00","type":"TICKETING"}],"grandTotal":"12632.45"},"pricingOptions":{"fareType":["PUBLISHED"],"includedCheckedBagsOnly":true},"validatingAirlineCodes":["QR"],"travelerPricings":[{"travelerId":"1","fareOption":"STANDARD","travelerType":"ADULT","price":{"currency":"ZAR","total":"12632.45","base":"6370.00"},"fareDetailsBySegment":[{"segmentId":"1","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"2","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"7","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"8","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}}]}]},{"type":"flight-offer","id":"3","source":"GDS","instantTicketingRequired":false,"nonHomogeneous":false,"oneWay":false,"lastTicketingDate":"2023-03-01","numberOfBookableSeats":7,"itineraries":[{"duration":"PT25H30M","segments":[{"departure":{"iataCode":"CPT","at":"2023-03-01T12:55:00"},"arrival":{"iataCode":"DOH","at":"2023-03-01T23:40:00"},"carrierCode":"QR","number":"1372","aircraft":{"code":"77W"},"operating":{"carrierCode":"QR"},"duration":"PT9H45M","id":"3","numberOfStops":0,"blacklistedInEU":false},{"departure":{"iataCode":"DOH","at":"2023-03-02T08:05:00"},"arrival":{"iataCode":"LGW","terminal":"N","at":"2023-03-02T12:25:00"},"carrierCode":"QR","number":"327","aircraft":{"code":"788"},"operating":{"carrierCode":"QR"},"duration":"PT7H20M","id":"4","numberOfStops":0,"blacklistedInEU":false}]},{"duration":"PT19H10M","segments":[{"departure":{"iataCode":"LGW","terminal":"S","at":"2023-03-08T14:05:00"},"arrival":{"iataCode":"DOH","at":"2023-03-08T23:45:00"},"carrierCode":"QR","number":"5942","aircraft":{"code":"777"},"operating":{"carrierCode":"BA"},"duration":"PT6H40M","id":"7","numberOfStops":0,"blacklistedInEU":false},{"departure":{"iataCode":"DOH","at":"2023-03-09T02:15:00"},"arrival":{"iataCode":"CPT","at":"2023-03-09T11:15:00"},"carrierCode":"QR","number":"1369","aircraft":{"code":"77W"},"operating":{"carrierCode":"QR"},"duration":"PT10H","id":"8","numberOfStops":0,"blacklistedInEU":false}]}],"price":{"currency":"ZAR","total":"12632.45","base":"6370.00","fees":[{"amount":"0.00","type":"SUPPLIER"},{"amount":"0.00","type":"TICKETING"}],"grandTotal":"12632.45"},"pricingOptions":{"fareType":["PUBLISHED"],"includedCheckedBagsOnly":true},"validatingAirlineCodes":["QR"],"travelerPricings":[{"travelerId":"1","fareOption":"STANDARD","travelerType":"ADULT","price":{"currency":"ZAR","total":"12632.45","base":"6370.00"},"fareDetailsBySegment":[{"segmentId":"3","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"4","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"7","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"8","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}}]}]},{"type":"flight-offer","id":"4","source":"GDS","instantTicketingRequired":false,"nonHomogeneous":false,"oneWay":false,"lastTicketingDate":"2023-03-01","numberOfBookableSeats":7,"itineraries":[{"duration":"PT18H50M","segments":[{"departure":{"iataCode":"CPT","at":"2023-03-01T12:55:00"},"arrival":{"iataCode":"DOH","at":"2023-03-01T23:40:00"},"carrierCode":"QR","number":"1372","aircraft":{"code":"77W"},"operating":{"carrierCode":"QR"},"duration":"PT9H45M","id":"5","numberOfStops":0,"blacklistedInEU":false},{"departure":{"iataCode":"DOH","at":"2023-03-02T01:15:00"},"arrival":{"iataCode":"LGW","terminal":"S","at":"2023-03-02T05:45:00"},"carrierCode":"QR","number":"5943","aircraft":{"code":"777"},"operating":{"carrierCode":"BA"},"duration":"PT7H30M","id":"6","numberOfStops":0,"blacklistedInEU":false}]},{"duration":"PT19H10M","segments":[{"departure":{"iataCode":"LGW","terminal":"N","at":"2023-03-08T14:05:00"},"arrival":{"iataCode":"DOH","at":"2023-03-08T23:50:00"},"carrierCode":"QR","number":"328","aircraft":{"code":"788"},"operating":{"carrierCode":"QR"},"duration":"PT6H45M","id":"9","numberOfStops":0,"blacklistedInEU":false},{"departure":{"iataCode":"DOH","at":"2023-03-09T02:15:00"},"arrival":{"iataCode":"CPT","at":"2023-03-09T11:15:00"},"carrierCode":"QR","number":"1369","aircraft":{"code":"77W"},"operating":{"carrierCode":"QR"},"duration":"PT10H","id":"10","numberOfStops":0,"blacklistedInEU":false}]}],"price":{"currency":"ZAR","total":"12670.45","base":"6370.00","fees":[{"amount":"0.00","type":"SUPPLIER"},{"amount":"0.00","type":"TICKETING"}],"grandTotal":"12670.45"},"pricingOptions":{"fareType":["PUBLISHED"],"includedCheckedBagsOnly":true},"validatingAirlineCodes":["QR"],"travelerPricings":[{"travelerId":"1","fareOption":"STANDARD","travelerType":"ADULT","price":{"currency":"ZAR","total":"12670.45","base":"6370.00"},"fareDetailsBySegment":[{"segmentId":"5","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"6","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"9","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"10","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}}]}]},{"type":"flight-offer","id":"5","source":"GDS","instantTicketingRequired":false,"nonHomogeneous":false,"oneWay":false,"lastTicketingDate":"2023-03-01","numberOfBookableSeats":9,"itineraries":[{"duration":"PT19H15M","segments":[{"departure":{"iataCode":"CPT","at":"2023-03-01T19:10:00"},"arrival":{"iataCode":"DOH","at":"2023-03-02T05:55:00"},"carrierCode":"QR","number":"1370","aircraft":{"code":"77W"},"operating":{"carrierCode":"QR"},"duration":"PT9H45M","id":"1","numberOfStops":0,"blacklistedInEU":false},{"departure":{"iataCode":"DOH","at":"2023-03-02T08:05:00"},"arrival":{"iataCode":"LGW","terminal":"N","at":"2023-03-02T12:25:00"},"carrierCode":"QR","number":"327","aircraft":{"code":"788"},"operating":{"carrierCode":"QR"},"duration":"PT7H20M","id":"2","numberOfStops":0,"blacklistedInEU":false}]},{"duration":"PT19H10M","segments":[{"departure":{"iataCode":"LGW","terminal":"N","at":"2023-03-08T14:05:00"},"arrival":{"iataCode":"DOH","at":"2023-03-08T23:50:00"},"carrierCode":"QR","number":"328","aircraft":{"code":"788"},"operating":{"carrierCode":"QR"},"duration":"PT6H45M","id":"9","numberOfStops":0,"blacklistedInEU":false},{"departure":{"iataCode":"DOH","at":"2023-03-09T02:15:00"},"arrival":{"iataCode":"CPT","at":"2023-03-09T11:15:00"},"carrierCode":"QR","number":"1369","aircraft":{"code":"77W"},"operating":{"carrierCode":"QR"},"duration":"PT10H","id":"10","numberOfStops":0,"blacklistedInEU":false}]}],"price":{"currency":"ZAR","total":"12670.45","base":"6370.00","fees":[{"amount":"0.00","type":"SUPPLIER"},{"amount":"0.00","type":"TICKETING"}],"grandTotal":"12670.45"},"pricingOptions":{"fareType":["PUBLISHED"],"includedCheckedBagsOnly":true},"validatingAirlineCodes":["QR"],"travelerPricings":[{"travelerId":"1","fareOption":"STANDARD","travelerType":"ADULT","price":{"currency":"ZAR","total":"12670.45","base":"6370.00"},"fareDetailsBySegment":[{"segmentId":"1","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"2","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"9","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"10","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}}]}]}],"dictionaries":{"locations":{"CPT":{"cityCode":"CPT","countryCode":"ZA"},"DOH":{"cityCode":"DOH","countryCode":"QA"},"LGW":{"cityCode":"LON","countryCode":"GB"}},"aircraft":{"77W":"BOEING 777-300ER","777":"BOEING 777-200/300","788":"BOEING 787-8"},"currencies":{"ZAR":"S.AFRICAN RAND"},"carriers":{"QR":"QATAR AIRWAYS","BA":"BRITISH AIRWAYS"}}}Array ( [0] => meta [1] => data [2] => dictionaries ) 

Thanks for your patience...

Link to comment
Share on other sites

$objects['data'] contains your list of offers, so you loop over that and in each iteration you would produce one of your table outputs.

foreach ($objects['data'] as $offer){
    $html = buildOfferTable($offer);
}

Within each offer, you have your different itineraries.  I'm presuming there will be one itinerary if it is oneWay: true, two otherwise.  I'm also presuming the first itinerary is the trip there, second is return trip.   If you just want to do a single set of rows like in your picture for both trips, then loop over the itineraries array and then the segments array.

foreach ($offer['itineraries'] as $itin){
   foreach ($itin['segments'] as $seg){
      $row = createSegmentRow($seg);
   }
}

With $seg, you can start extracting the details, for example:

$departCode=$seg['departure']['iataCode'];
$arriveCode=$seg['arrival']['iataCode'];
$carrierCode=$seg['carrierCode'];
$number=$seg['number'];
//...

 

Link to comment
Share on other sites

Hi Kicku,

Many thanks for your input . Your assumptions are quite correct in that the amount of itineraries could vary depending on what flights are available to get to the d. Some may more than one connecting point and some none at all. This query I am doing is merely to show what flights are available on the given days  and the total price. The user then makes a selection and the next step (which I am still to do) is to get the final price... so that is the flow..

I will play around with what you have provide and thank you once agai...

 ..                

Link to comment
Share on other sites

Hi Barand... I did.. I have also saved it in a json file which I unfortunately cannot upload here post here. I have redone and pasted it here

{"meta":{"count":5,"links":{"self":"https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=CPT&destinationLocationCode=LGW&departureDate=2023-03-01&returnDate=2023-03-08&adults=1&travelClass=ECONOMY¤cyCode=ZAR&max=5"}},"data":[{"type":"flight-offer","id":"1","source":"GDS","instantTicketingRequired":false,"nonHomogeneous":false,"oneWay":false,"lastTicketingDate":"2023-03-01","numberOfBookableSeats":7,"itineraries":[{"duration":"PT18H50M","segments":[{"departure":{"iataCode":"CPT","at":"2023-03-01T12:55:00"},"arrival":{"iataCode":"DOH","at":"2023-03-01T23:40:00"},"carrierCode":"QR","number":"1372","aircraft":{"code":"77W"},"operating":{"carrierCode":"QR"},"duration":"PT9H45M","id":"5","numberOfStops":0,"blacklistedInEU":false},{"departure":{"iataCode":"DOH","at":"2023-03-02T01:15:00"},"arrival":{"iataCode":"LGW","terminal":"S","at":"2023-03-02T05:45:00"},"carrierCode":"QR","number":"5943","aircraft":{"code":"777"},"operating":{"carrierCode":"BA"},"duration":"PT7H30M","id":"6","numberOfStops":0,"blacklistedInEU":false}]},{"duration":"PT19H10M","segments":[{"departure":{"iataCode":"LGW","terminal":"S","at":"2023-03-08T14:05:00"},"arrival":{"iataCode":"DOH","at":"2023-03-08T23:45:00"},"carrierCode":"QR","number":"5942","aircraft":{"code":"777"},"operating":{"carrierCode":"BA"},"duration":"PT6H40M","id":"7","numberOfStops":0,"blacklistedInEU":false},{"departure":{"iataCode":"DOH","at":"2023-03-09T02:15:00"},"arrival":{"iataCode":"CPT","at":"2023-03-09T11:15:00"},"carrierCode":"QR","number":"1369","aircraft":{"code":"77W"},"operating":{"carrierCode":"QR"},"duration":"PT10H","id":"8","numberOfStops":0,"blacklistedInEU":false}]}],"price":{"currency":"ZAR","total":"12632.45","base":"6370.00","fees":[{"amount":"0.00","type":"SUPPLIER"},{"amount":"0.00","type":"TICKETING"}],"grandTotal":"12632.45"},"pricingOptions":{"fareType":["PUBLISHED"],"includedCheckedBagsOnly":true},"validatingAirlineCodes":["QR"],"travelerPricings":[{"travelerId":"1","fareOption":"STANDARD","travelerType":"ADULT","price":{"currency":"ZAR","total":"12632.45","base":"6370.00"},"fareDetailsBySegment":[{"segmentId":"5","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"6","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"7","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"8","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}}]}]},{"type":"flight-offer","id":"2","source":"GDS","instantTicketingRequired":false,"nonHomogeneous":false,"oneWay":false,"lastTicketingDate":"2023-03-01","numberOfBookableSeats":7,"itineraries":[{"duration":"PT19H15M","segments":[{"departure":{"iataCode":"CPT","at":"2023-03-01T19:10:00"},"arrival":{"iataCode":"DOH","at":"2023-03-02T05:55:00"},"carrierCode":"QR","number":"1370","aircraft":{"code":"77W"},"operating":{"carrierCode":"QR"},"duration":"PT9H45M","id":"1","numberOfStops":0,"blacklistedInEU":false},{"departure":{"iataCode":"DOH","at":"2023-03-02T08:05:00"},"arrival":{"iataCode":"LGW","terminal":"N","at":"2023-03-02T12:25:00"},"carrierCode":"QR","number":"327","aircraft":{"code":"788"},"operating":{"carrierCode":"QR"},"duration":"PT7H20M","id":"2","numberOfStops":0,"blacklistedInEU":false}]},{"duration":"PT19H10M","segments":[{"departure":{"iataCode":"LGW","terminal":"S","at":"2023-03-08T14:05:00"},"arrival":{"iataCode":"DOH","at":"2023-03-08T23:45:00"},"carrierCode":"QR","number":"5942","aircraft":{"code":"777"},"operating":{"carrierCode":"BA"},"duration":"PT6H40M","id":"7","numberOfStops":0,"blacklistedInEU":false},{"departure":{"iataCode":"DOH","at":"2023-03-09T02:15:00"},"arrival":{"iataCode":"CPT","at":"2023-03-09T11:15:00"},"carrierCode":"QR","number":"1369","aircraft":{"code":"77W"},"operating":{"carrierCode":"QR"},"duration":"PT10H","id":"8","numberOfStops":0,"blacklistedInEU":false}]}],"price":{"currency":"ZAR","total":"12632.45","base":"6370.00","fees":[{"amount":"0.00","type":"SUPPLIER"},{"amount":"0.00","type":"TICKETING"}],"grandTotal":"12632.45"},"pricingOptions":{"fareType":["PUBLISHED"],"includedCheckedBagsOnly":true},"validatingAirlineCodes":["QR"],"travelerPricings":[{"travelerId":"1","fareOption":"STANDARD","travelerType":"ADULT","price":{"currency":"ZAR","total":"12632.45","base":"6370.00"},"fareDetailsBySegment":[{"segmentId":"1","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"2","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"7","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"8","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}}]}]},{"type":"flight-offer","id":"3","source":"GDS","instantTicketingRequired":false,"nonHomogeneous":false,"oneWay":false,"lastTicketingDate":"2023-03-01","numberOfBookableSeats":7,"itineraries":[{"duration":"PT25H30M","segments":[{"departure":{"iataCode":"CPT","at":"2023-03-01T12:55:00"},"arrival":{"iataCode":"DOH","at":"2023-03-01T23:40:00"},"carrierCode":"QR","number":"1372","aircraft":{"code":"77W"},"operating":{"carrierCode":"QR"},"duration":"PT9H45M","id":"3","numberOfStops":0,"blacklistedInEU":false},{"departure":{"iataCode":"DOH","at":"2023-03-02T08:05:00"},"arrival":{"iataCode":"LGW","terminal":"N","at":"2023-03-02T12:25:00"},"carrierCode":"QR","number":"327","aircraft":{"code":"788"},"operating":{"carrierCode":"QR"},"duration":"PT7H20M","id":"4","numberOfStops":0,"blacklistedInEU":false}]},{"duration":"PT19H10M","segments":[{"departure":{"iataCode":"LGW","terminal":"S","at":"2023-03-08T14:05:00"},"arrival":{"iataCode":"DOH","at":"2023-03-08T23:45:00"},"carrierCode":"QR","number":"5942","aircraft":{"code":"777"},"operating":{"carrierCode":"BA"},"duration":"PT6H40M","id":"7","numberOfStops":0,"blacklistedInEU":false},{"departure":{"iataCode":"DOH","at":"2023-03-09T02:15:00"},"arrival":{"iataCode":"CPT","at":"2023-03-09T11:15:00"},"carrierCode":"QR","number":"1369","aircraft":{"code":"77W"},"operating":{"carrierCode":"QR"},"duration":"PT10H","id":"8","numberOfStops":0,"blacklistedInEU":false}]}],"price":{"currency":"ZAR","total":"12632.45","base":"6370.00","fees":[{"amount":"0.00","type":"SUPPLIER"},{"amount":"0.00","type":"TICKETING"}],"grandTotal":"12632.45"},"pricingOptions":{"fareType":["PUBLISHED"],"includedCheckedBagsOnly":true},"validatingAirlineCodes":["QR"],"travelerPricings":[{"travelerId":"1","fareOption":"STANDARD","travelerType":"ADULT","price":{"currency":"ZAR","total":"12632.45","base":"6370.00"},"fareDetailsBySegment":[{"segmentId":"3","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"4","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"7","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"8","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}}]}]},{"type":"flight-offer","id":"4","source":"GDS","instantTicketingRequired":false,"nonHomogeneous":false,"oneWay":false,"lastTicketingDate":"2023-03-01","numberOfBookableSeats":7,"itineraries":[{"duration":"PT18H50M","segments":[{"departure":{"iataCode":"CPT","at":"2023-03-01T12:55:00"},"arrival":{"iataCode":"DOH","at":"2023-03-01T23:40:00"},"carrierCode":"QR","number":"1372","aircraft":{"code":"77W"},"operating":{"carrierCode":"QR"},"duration":"PT9H45M","id":"5","numberOfStops":0,"blacklistedInEU":false},{"departure":{"iataCode":"DOH","at":"2023-03-02T01:15:00"},"arrival":{"iataCode":"LGW","terminal":"S","at":"2023-03-02T05:45:00"},"carrierCode":"QR","number":"5943","aircraft":{"code":"777"},"operating":{"carrierCode":"BA"},"duration":"PT7H30M","id":"6","numberOfStops":0,"blacklistedInEU":false}]},{"duration":"PT19H10M","segments":[{"departure":{"iataCode":"LGW","terminal":"N","at":"2023-03-08T14:05:00"},"arrival":{"iataCode":"DOH","at":"2023-03-08T23:50:00"},"carrierCode":"QR","number":"328","aircraft":{"code":"788"},"operating":{"carrierCode":"QR"},"duration":"PT6H45M","id":"9","numberOfStops":0,"blacklistedInEU":false},{"departure":{"iataCode":"DOH","at":"2023-03-09T02:15:00"},"arrival":{"iataCode":"CPT","at":"2023-03-09T11:15:00"},"carrierCode":"QR","number":"1369","aircraft":{"code":"77W"},"operating":{"carrierCode":"QR"},"duration":"PT10H","id":"10","numberOfStops":0,"blacklistedInEU":false}]}],"price":{"currency":"ZAR","total":"12670.45","base":"6370.00","fees":[{"amount":"0.00","type":"SUPPLIER"},{"amount":"0.00","type":"TICKETING"}],"grandTotal":"12670.45"},"pricingOptions":{"fareType":["PUBLISHED"],"includedCheckedBagsOnly":true},"validatingAirlineCodes":["QR"],"travelerPricings":[{"travelerId":"1","fareOption":"STANDARD","travelerType":"ADULT","price":{"currency":"ZAR","total":"12670.45","base":"6370.00"},"fareDetailsBySegment":[{"segmentId":"5","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"6","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"9","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"10","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}}]}]},{"type":"flight-offer","id":"5","source":"GDS","instantTicketingRequired":false,"nonHomogeneous":false,"oneWay":false,"lastTicketingDate":"2023-03-01","numberOfBookableSeats":9,"itineraries":[{"duration":"PT19H15M","segments":[{"departure":{"iataCode":"CPT","at":"2023-03-01T19:10:00"},"arrival":{"iataCode":"DOH","at":"2023-03-02T05:55:00"},"carrierCode":"QR","number":"1370","aircraft":{"code":"77W"},"operating":{"carrierCode":"QR"},"duration":"PT9H45M","id":"1","numberOfStops":0,"blacklistedInEU":false},{"departure":{"iataCode":"DOH","at":"2023-03-02T08:05:00"},"arrival":{"iataCode":"LGW","terminal":"N","at":"2023-03-02T12:25:00"},"carrierCode":"QR","number":"327","aircraft":{"code":"788"},"operating":{"carrierCode":"QR"},"duration":"PT7H20M","id":"2","numberOfStops":0,"blacklistedInEU":false}]},{"duration":"PT19H10M","segments":[{"departure":{"iataCode":"LGW","terminal":"N","at":"2023-03-08T14:05:00"},"arrival":{"iataCode":"DOH","at":"2023-03-08T23:50:00"},"carrierCode":"QR","number":"328","aircraft":{"code":"788"},"operating":{"carrierCode":"QR"},"duration":"PT6H45M","id":"9","numberOfStops":0,"blacklistedInEU":false},{"departure":{"iataCode":"DOH","at":"2023-03-09T02:15:00"},"arrival":{"iataCode":"CPT","at":"2023-03-09T11:15:00"},"carrierCode":"QR","number":"1369","aircraft":{"code":"77W"},"operating":{"carrierCode":"QR"},"duration":"PT10H","id":"10","numberOfStops":0,"blacklistedInEU":false}]}],"price":{"currency":"ZAR","total":"12670.45","base":"6370.00","fees":[{"amount":"0.00","type":"SUPPLIER"},{"amount":"0.00","type":"TICKETING"}],"grandTotal":"12670.45"},"pricingOptions":{"fareType":["PUBLISHED"],"includedCheckedBagsOnly":true},"validatingAirlineCodes":["QR"],"travelerPricings":[{"travelerId":"1","fareOption":"STANDARD","travelerType":"ADULT","price":{"currency":"ZAR","total":"12670.45","base":"6370.00"},"fareDetailsBySegment":[{"segmentId":"1","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"2","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"9","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"10","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}}]}]}],"dictionaries":{"locations":{"CPT":{"cityCode":"CPT","countryCode":"ZA"},"DOH":{"cityCode":"DOH","countryCode":"QA"},"LGW":{"cityCode":"LON","countryCode":"GB"}},"aircraft":{"77W":"BOEING 777-300ER","777":"BOEING 777-200/300","788":"BOEING 787-8"},"currencies":{"ZAR":"S.AFRICAN RAND"},"carriers":{"QR":"QATAR AIRWAYS","BA":"BRITISH AIRWAYS"}}}Array ( [0] => meta [1] => data [2] => dictionaries // JavaScript Document

 

Link to comment
Share on other sites

The end of the string that you just posted contained stuff that shouldn't be there in the json data

. . . ,"carriers":{"QR":"QATAR AIRWAYS","BA":"BRITISH AIRWAYS"}}}Array ( [0] => meta [1] => data [2] => dictionaries // JavaScript Document
                                                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^            

Once I removed the offending text, it decoded without error.

BTW, for future reference when using print_r(), put it inside <pre>..</pre> tags to get readable structured output. For example

$array = json_decode($json, true);
echo '<pre>' . print_r($array, 1) . '</pre>';  

 

Link to comment
Share on other sites

HI Barsnd... Noted and thanks for that info... We live and learn :)

I was trying , and still am, with the code that Kicken posted and am not having much success. I am wondering if that text you removed would be the reason but am not finished yet... am working my way through it slowly so I get to understand what is what...

Link to comment
Share on other sites

I was going through the code Kicken provided and was receiving undefined variable error on each set of code so I started fiddling to see if I could get somewhere.  Right now I have the code below producing the correct amount of rows but they all contain the same record Id and details.. I saw that same of the items required were deeply nested (I think that's the right term). I thin k my foreach statement is wrong so was playing with then when the queries started timing out with this error. in a file I have not even touched

Fatal error: Uncaught WpOrg\Requests\Exception: cURL error 28: Operation timed out after 10003 milliseconds with 0 bytes received in C:\wamp64\www\fares\requests\src\Transport\Curl.php on line 490.

The reference row in the error is the error related to it above quere as follow

if (curl_errno($this->handle)) {
			$error = sprintf(
				'cURL error %s: %s',
				curl_errno($this->handle),
				curl_error($this->handle)
			);
	ROW 490		throw new Exception($error, 'curlerror', $this->handle);

The code I was working with is as follows and as I say it was producing the required amount of rows for each record but the same detail on each row

<?php
foreach ($objects['data'] as $id){
																	
$source =$objects['data']['0']['source'];
$offer_id = $objects['data']['0']['id'];
$offer_source = $objects['data']['0']['source'];
$sector_price =  $objects['data']['0']['price']['total'];
$price_currency = $objects['data']['0']['price']['currency'];
$departure_iataCode = $objects['data']['0']['itineraries']['0']['segments']['0']['departure']['iataCode'];
 $duration =  $objects['data']['0']['itineraries']['0']['duration'];
$arriva_iataCode = $objects['data']['0']['itineraries']['0']['segments']['0']['arrival']['iataCode'];
$departure_DateTime = $objects['data']['0']['itineraries']['0']['segments']['0']['departure']['at']; 
$arrival_DateTime = $objects['data']['0']['itineraries']['0']['segments']['0']['arrival']['at']; 
$carrierCodeNumber = $objects['data']['0']['itineraries']['0']['segments']['0']['carrierCode']."-".$objects['data']['0']['itineraries']['0']['segments']['0']['number'];
$$duration = $objects['data']['0']['itineraries']['0']['duration'];
$operatedBy = $objects['data']['0']['itineraries']['0']['segments']['0']['operating']['carrierCode'];

  echo"
  <table width=\"70%\" align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
 <tr>
   <td align=\"center\"><div align=\"center\"><b>Offer id :</b>{$offer_id}</div></td>
   <td>&nbsp;</td>
   <td align=\"center\"><div align=\"center\"><b>Source :</b>{$offer_source}</div></td>
   <td>&nbsp;</td>
   <td style=\"font-weight: bold;\"><div align=\"center\">Total price :{$sector_price} in {$price_currency}</div></td>
        <td>&nbsp;</td>
<tr bgcolor=\"#005EB8\" style=\"color: white;\">
        <th>Segment</th>
  <td>&nbsp;</td>
        <td align=\"center\">Departure Date / Time</td>
        <td>&nbsp;</td>
        <td align=\"center\">Flight number</td>
        <td>&nbsp;</td>
        <th>Departure Time</td>
        <td>&nbsp;</td>
        <td align=\"center\">Arrival Time</td>
        <td>&nbsp;</td>
        <td align=\"center\">Duration</td>
        <td>&nbsp;</td>
        <td align=\"center\">Operated By</td>
</tr>
															
<tr>
		<td align=\"center\">{$departure_iataCode}-{$arriva_iataCode}</td>
		<td>&nbsp;</td>
		<td align=\"center\">{$departure_DateTime}</td>
		<td>&nbsp;</td>
		<td align=\"center\">{$carrierCodeNumber}</td>
		<td>&nbsp;</td>
		<td align=\"center\">{$departure_DateTime}</td>
		<td>&nbsp;</td>
		<td align=\"center\">{$arrival_DateTime}</td>
		<td>&nbsp;</td>
		<td align=\"center\">{$duration}</td>
		<td>&nbsp;</td>
		<td align=\"center\">{$operatedBy }</td>
	</tr>
	 <table>";
}	 
	 
?>

That is where I am at now so now trying to see why all of a sudden the timeout occurs

Link to comment
Share on other sites

  • Solution

It's been  a particularly miserable , grey, rainy sort of a day so I passed some time on this

<?php
$json = '{"meta":{"count":5,"links":{"self":"https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=CPT&destinationLocationCode=LGW&departureDate=2023-03-01&returnDate=2023-03-08&adults=1&travelClass=ECONOMY¤cyCode=ZAR&max=5"}},"data":[{"type":"flight-offer","id":"1","source":"GDS","instantTicketingRequired":false,"nonHomogeneous":false,"oneWay":false,"lastTicketingDate":"2023-03-01","numberOfBookableSeats":7,"itineraries":[{"duration":"PT18H50M","segments":[{"departure":{"iataCode":"CPT","at":"2023-03-01T12:55:00"},"arrival":{"iataCode":"DOH","at":"2023-03-01T23:40:00"},"carrierCode":"QR","number":"1372","aircraft":{"code":"77W"},"operating":{"carrierCode":"QR"},"duration":"PT9H45M","id":"5","numberOfStops":0,"blacklistedInEU":false},{"departure":{"iataCode":"DOH","at":"2023-03-02T01:15:00"},"arrival":{"iataCode":"LGW","terminal":"S","at":"2023-03-02T05:45:00"},"carrierCode":"QR","number":"5943","aircraft":{"code":"777"},"operating":{"carrierCode":"BA"},"duration":"PT7H30M","id":"6","numberOfStops":0,"blacklistedInEU":false}]},{"duration":"PT19H10M","segments":[{"departure":{"iataCode":"LGW","terminal":"S","at":"2023-03-08T14:05:00"},"arrival":{"iataCode":"DOH","at":"2023-03-08T23:45:00"},"carrierCode":"QR","number":"5942","aircraft":{"code":"777"},"operating":{"carrierCode":"BA"},"duration":"PT6H40M","id":"7","numberOfStops":0,"blacklistedInEU":false},{"departure":{"iataCode":"DOH","at":"2023-03-09T02:15:00"},"arrival":{"iataCode":"CPT","at":"2023-03-09T11:15:00"},"carrierCode":"QR","number":"1369","aircraft":{"code":"77W"},"operating":{"carrierCode":"QR"},"duration":"PT10H","id":"8","numberOfStops":0,"blacklistedInEU":false}]}],"price":{"currency":"ZAR","total":"12632.45","base":"6370.00","fees":[{"amount":"0.00","type":"SUPPLIER"},{"amount":"0.00","type":"TICKETING"}],"grandTotal":"12632.45"},"pricingOptions":{"fareType":["PUBLISHED"],"includedCheckedBagsOnly":true},"validatingAirlineCodes":["QR"],"travelerPricings":[{"travelerId":"1","fareOption":"STANDARD","travelerType":"ADULT","price":{"currency":"ZAR","total":"12632.45","base":"6370.00"},"fareDetailsBySegment":[{"segmentId":"5","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"6","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"7","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"8","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}}]}]},{"type":"flight-offer","id":"2","source":"GDS","instantTicketingRequired":false,"nonHomogeneous":false,"oneWay":false,"lastTicketingDate":"2023-03-01","numberOfBookableSeats":7,"itineraries":[{"duration":"PT19H15M","segments":[{"departure":{"iataCode":"CPT","at":"2023-03-01T19:10:00"},"arrival":{"iataCode":"DOH","at":"2023-03-02T05:55:00"},"carrierCode":"QR","number":"1370","aircraft":{"code":"77W"},"operating":{"carrierCode":"QR"},"duration":"PT9H45M","id":"1","numberOfStops":0,"blacklistedInEU":false},{"departure":{"iataCode":"DOH","at":"2023-03-02T08:05:00"},"arrival":{"iataCode":"LGW","terminal":"N","at":"2023-03-02T12:25:00"},"carrierCode":"QR","number":"327","aircraft":{"code":"788"},"operating":{"carrierCode":"QR"},"duration":"PT7H20M","id":"2","numberOfStops":0,"blacklistedInEU":false}]},{"duration":"PT19H10M","segments":[{"departure":{"iataCode":"LGW","terminal":"S","at":"2023-03-08T14:05:00"},"arrival":{"iataCode":"DOH","at":"2023-03-08T23:45:00"},"carrierCode":"QR","number":"5942","aircraft":{"code":"777"},"operating":{"carrierCode":"BA"},"duration":"PT6H40M","id":"7","numberOfStops":0,"blacklistedInEU":false},{"departure":{"iataCode":"DOH","at":"2023-03-09T02:15:00"},"arrival":{"iataCode":"CPT","at":"2023-03-09T11:15:00"},"carrierCode":"QR","number":"1369","aircraft":{"code":"77W"},"operating":{"carrierCode":"QR"},"duration":"PT10H","id":"8","numberOfStops":0,"blacklistedInEU":false}]}],"price":{"currency":"ZAR","total":"12632.45","base":"6370.00","fees":[{"amount":"0.00","type":"SUPPLIER"},{"amount":"0.00","type":"TICKETING"}],"grandTotal":"12632.45"},"pricingOptions":{"fareType":["PUBLISHED"],"includedCheckedBagsOnly":true},"validatingAirlineCodes":["QR"],"travelerPricings":[{"travelerId":"1","fareOption":"STANDARD","travelerType":"ADULT","price":{"currency":"ZAR","total":"12632.45","base":"6370.00"},"fareDetailsBySegment":[{"segmentId":"1","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"2","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"7","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"8","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}}]}]},{"type":"flight-offer","id":"3","source":"GDS","instantTicketingRequired":false,"nonHomogeneous":false,"oneWay":false,"lastTicketingDate":"2023-03-01","numberOfBookableSeats":7,"itineraries":[{"duration":"PT25H30M","segments":[{"departure":{"iataCode":"CPT","at":"2023-03-01T12:55:00"},"arrival":{"iataCode":"DOH","at":"2023-03-01T23:40:00"},"carrierCode":"QR","number":"1372","aircraft":{"code":"77W"},"operating":{"carrierCode":"QR"},"duration":"PT9H45M","id":"3","numberOfStops":0,"blacklistedInEU":false},{"departure":{"iataCode":"DOH","at":"2023-03-02T08:05:00"},"arrival":{"iataCode":"LGW","terminal":"N","at":"2023-03-02T12:25:00"},"carrierCode":"QR","number":"327","aircraft":{"code":"788"},"operating":{"carrierCode":"QR"},"duration":"PT7H20M","id":"4","numberOfStops":0,"blacklistedInEU":false}]},{"duration":"PT19H10M","segments":[{"departure":{"iataCode":"LGW","terminal":"S","at":"2023-03-08T14:05:00"},"arrival":{"iataCode":"DOH","at":"2023-03-08T23:45:00"},"carrierCode":"QR","number":"5942","aircraft":{"code":"777"},"operating":{"carrierCode":"BA"},"duration":"PT6H40M","id":"7","numberOfStops":0,"blacklistedInEU":false},{"departure":{"iataCode":"DOH","at":"2023-03-09T02:15:00"},"arrival":{"iataCode":"CPT","at":"2023-03-09T11:15:00"},"carrierCode":"QR","number":"1369","aircraft":{"code":"77W"},"operating":{"carrierCode":"QR"},"duration":"PT10H","id":"8","numberOfStops":0,"blacklistedInEU":false}]}],"price":{"currency":"ZAR","total":"12632.45","base":"6370.00","fees":[{"amount":"0.00","type":"SUPPLIER"},{"amount":"0.00","type":"TICKETING"}],"grandTotal":"12632.45"},"pricingOptions":{"fareType":["PUBLISHED"],"includedCheckedBagsOnly":true},"validatingAirlineCodes":["QR"],"travelerPricings":[{"travelerId":"1","fareOption":"STANDARD","travelerType":"ADULT","price":{"currency":"ZAR","total":"12632.45","base":"6370.00"},"fareDetailsBySegment":[{"segmentId":"3","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"4","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"7","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"8","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}}]}]},{"type":"flight-offer","id":"4","source":"GDS","instantTicketingRequired":false,"nonHomogeneous":false,"oneWay":false,"lastTicketingDate":"2023-03-01","numberOfBookableSeats":7,"itineraries":[{"duration":"PT18H50M","segments":[{"departure":{"iataCode":"CPT","at":"2023-03-01T12:55:00"},"arrival":{"iataCode":"DOH","at":"2023-03-01T23:40:00"},"carrierCode":"QR","number":"1372","aircraft":{"code":"77W"},"operating":{"carrierCode":"QR"},"duration":"PT9H45M","id":"5","numberOfStops":0,"blacklistedInEU":false},{"departure":{"iataCode":"DOH","at":"2023-03-02T01:15:00"},"arrival":{"iataCode":"LGW","terminal":"S","at":"2023-03-02T05:45:00"},"carrierCode":"QR","number":"5943","aircraft":{"code":"777"},"operating":{"carrierCode":"BA"},"duration":"PT7H30M","id":"6","numberOfStops":0,"blacklistedInEU":false}]},{"duration":"PT19H10M","segments":[{"departure":{"iataCode":"LGW","terminal":"N","at":"2023-03-08T14:05:00"},"arrival":{"iataCode":"DOH","at":"2023-03-08T23:50:00"},"carrierCode":"QR","number":"328","aircraft":{"code":"788"},"operating":{"carrierCode":"QR"},"duration":"PT6H45M","id":"9","numberOfStops":0,"blacklistedInEU":false},{"departure":{"iataCode":"DOH","at":"2023-03-09T02:15:00"},"arrival":{"iataCode":"CPT","at":"2023-03-09T11:15:00"},"carrierCode":"QR","number":"1369","aircraft":{"code":"77W"},"operating":{"carrierCode":"QR"},"duration":"PT10H","id":"10","numberOfStops":0,"blacklistedInEU":false}]}],"price":{"currency":"ZAR","total":"12670.45","base":"6370.00","fees":[{"amount":"0.00","type":"SUPPLIER"},{"amount":"0.00","type":"TICKETING"}],"grandTotal":"12670.45"},"pricingOptions":{"fareType":["PUBLISHED"],"includedCheckedBagsOnly":true},"validatingAirlineCodes":["QR"],"travelerPricings":[{"travelerId":"1","fareOption":"STANDARD","travelerType":"ADULT","price":{"currency":"ZAR","total":"12670.45","base":"6370.00"},"fareDetailsBySegment":[{"segmentId":"5","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"6","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"9","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"10","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}}]}]},{"type":"flight-offer","id":"5","source":"GDS","instantTicketingRequired":false,"nonHomogeneous":false,"oneWay":false,"lastTicketingDate":"2023-03-01","numberOfBookableSeats":9,"itineraries":[{"duration":"PT19H15M","segments":[{"departure":{"iataCode":"CPT","at":"2023-03-01T19:10:00"},"arrival":{"iataCode":"DOH","at":"2023-03-02T05:55:00"},"carrierCode":"QR","number":"1370","aircraft":{"code":"77W"},"operating":{"carrierCode":"QR"},"duration":"PT9H45M","id":"1","numberOfStops":0,"blacklistedInEU":false},{"departure":{"iataCode":"DOH","at":"2023-03-02T08:05:00"},"arrival":{"iataCode":"LGW","terminal":"N","at":"2023-03-02T12:25:00"},"carrierCode":"QR","number":"327","aircraft":{"code":"788"},"operating":{"carrierCode":"QR"},"duration":"PT7H20M","id":"2","numberOfStops":0,"blacklistedInEU":false}]},{"duration":"PT19H10M","segments":[{"departure":{"iataCode":"LGW","terminal":"N","at":"2023-03-08T14:05:00"},"arrival":{"iataCode":"DOH","at":"2023-03-08T23:50:00"},"carrierCode":"QR","number":"328","aircraft":{"code":"788"},"operating":{"carrierCode":"QR"},"duration":"PT6H45M","id":"9","numberOfStops":0,"blacklistedInEU":false},{"departure":{"iataCode":"DOH","at":"2023-03-09T02:15:00"},"arrival":{"iataCode":"CPT","at":"2023-03-09T11:15:00"},"carrierCode":"QR","number":"1369","aircraft":{"code":"77W"},"operating":{"carrierCode":"QR"},"duration":"PT10H","id":"10","numberOfStops":0,"blacklistedInEU":false}]}],"price":{"currency":"ZAR","total":"12670.45","base":"6370.00","fees":[{"amount":"0.00","type":"SUPPLIER"},{"amount":"0.00","type":"TICKETING"}],"grandTotal":"12670.45"},"pricingOptions":{"fareType":["PUBLISHED"],"includedCheckedBagsOnly":true},"validatingAirlineCodes":["QR"],"travelerPricings":[{"travelerId":"1","fareOption":"STANDARD","travelerType":"ADULT","price":{"currency":"ZAR","total":"12670.45","base":"6370.00"},"fareDetailsBySegment":[{"segmentId":"1","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"2","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"9","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"10","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}}]}]}],"dictionaries":{"locations":{"CPT":{"cityCode":"CPT","countryCode":"ZA"},"DOH":{"cityCode":"DOH","countryCode":"QA"},"LGW":{"cityCode":"LON","countryCode":"GB"}},"aircraft":{"77W":"BOEING 777-300ER","777":"BOEING 777-200/300","788":"BOEING 787-8"},"currencies":{"ZAR":"S.AFRICAN RAND"},"carriers":{"QR":"QATAR AIRWAYS","BA":"BRITISH AIRWAYS"}}}';
$array = json_decode($json, true);

$html = '';
foreach ($array['data'] as $offer) {
    $html .= buildOfferTable($offer);
}

function buildOfferTable($offer)
{
    $html = "<div class='w3-row w3-padding w3-topbar'>
                 <div class='w3-col w3-quarter'>
                     Offer ID : {$offer['id']}
                 </div>
                 <div class='w3-col w3-quarter'>
                     Source : {$offer['source']}
                 </div>
                 <div class='w3-col w3-half'>
                     <b>Total Price : {$offer['price']['total']} {$offer['price']['currency']}</b>
                 </div>
             </div>
             <table class='w3-table w3-bordered'>
                  <tr class='w3-indigo'>
                    <th>Segment</th>
                    <th>Flight No</th>
                    <th>Departure Time</th>
                    <th>Arrival Time</th>
                  </tr>
            ";
    
    foreach ($offer['itineraries']as $itins) {
        foreach ($itins['segments'] as $segment) {
            $html .= segmentRow($segment);
        }
    }
    $html .= "</table>\n<br>";
    foreach ($offer['travelerPricings'] as $k => $tp) {
        $n = $k + 1;
        $html .= "Traveller $n : {$tp['travelerType']}<br>
                  Amount : {$tp['price']['total']} {$tp['price']['currency']}<br><br> 
                 ";
    }
               
                    
    return $html;
}

function segmentRow($segment)
{
    $dt = (new DateTime($segment['departure']['at']))->format('Y-m-d H:i');
    $at = (new DateTime($segment['arrival']['at']))->format('Y-m-d H:i');
    $row = "<tr>
                <td>{$segment['departure']['iataCode']}-{$segment['arrival']['iataCode']}</td>
                <td>{$segment['carrierCode']} {$segment['number']}</td>
                <td>$dt</td>
                <td>$at</td>
           </tr>
           ";
    return $row;
}
?>
<!DOCTYPE=html>
<html lang="en">
<head>
<meta charset='utf-8'>
<title>Flight Offers</title>
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"> 
</head>
<body>
<h1>Flight Offers</h1>
<div class='w3-content'>
    <?= $html ?>
</div>
</body>
</html>

producing 5 offers like this ...

image.png.fdcdc90c374b379fe2f08ae9d955f52e.png

  • Thanks 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.