I have a table with flight data in mysql. I'm writing a php code that will group and display data using codeigniter 3
journey_id air_id FlightDuration out_or_in flightduration2 1 1 20hr 5min outbound 1205 2 1 20hr 5min outbound 1300 3 1 17hr 55min inbound 2258 4 1 17hr 55min inbound 1075 5 2 31hr 40min outbound 1970 6 2 31hr 40min outbound 1900 7 2 17hr 55min inbound 2223 8 2 17hr 55min inbound 1987 9 3 10hr 45min outbound 645 10 3 11hr 25min inbound 685
I use $this->db->get()
to retrieve the data and I can loop easily. But since each row is in an array, I'm finding it difficult to group them. I can't use mysql groups because I need each row.
For example, I want to display the following items
air_id - 1 20hr 5min outbound 1205 20hr 5min outbound 1300 17hr 55min inbound 2258 17hr 55min inbound 1075 air_id - 2 31hr 40min outbound 1970 31hr 40min outbound 1900 17hr 55min inbound 2223 17hr 55min inbound 1987 air_id - 3 10hr 45min outbound 645 11hr 25min inbound 685
What is the best way to group the results by air_id
so that I can iterate over
Get data from database:
Create an empty array to save grouped data:
Iterate over the acquired data and group it by air_id:
Now you have the data grouped by air_id in the $grouped_data array. You can iterate through this array to display the data you specify:
This code will loop through the grouped data and display it as you describe, each group of flight data is under the corresponding air_id.