Page 1 of 1

Help with PHP tables for tide data

Posted: Mon 24 Jan 2022 4:27 pm
by Big Daddy
Hi,
Some general PHP help please on how to use a foreach loop for me to get tide data in a spefic table format.

I already use foreach loops for my forceast data and can use a foreach loop to get data in a table for the tides but I can only work out how to get one set of data on a row ( 4 x columns), which means it a very long table. Like so:

Day Event Time Height
Monday High Tide 09:10 6.9m
Monday Low Tide 21:15 0.6m
Tuesday High Tide 09:30 6.7m

etc.etc, you get the idea

What I would like to have is 3 sets of data on each row like this


Day Event Time Height Day Event Time Height Day Event Time Height
Monday High Tide 09:10 6.9m Monday Low Tide 21:15 0.6m Monday Low Tide 21:15 0.6m
Tuesday High Tide

You can see what I mean here, http://midlifedad.me.uk/weather/eastbourne_tides.phpbut when I first put this together, I hadnt learnt about "foreach" so literally created a variable from the json file for each entry and ended up having around 250 variables, not very efficient.

Data is being pulled from the UK Admiralty and it also uses Mark's charts to display. I'm ok formatting the actual data into days, times etc. But I can only get it to read the first foreach for each row so the data for each set of 4 colums is always the same on that row. (Hope that makes sense). Ive trawled through StackOverflow and many pages of php examples but cant find what I need.

Sample of the data from the json file is below.

[
{
"EventType": "LowWater",
"DateTime": "2022-01-24T05:10:00",
"IsApproximateTime": false,
"Height": 0.9433952546253683,
"IsApproximateHeight": false,
"Filtered": false,
"Date": "2022-01-24T00:00:00"
},
{
"EventType": "HighWater",
"DateTime": "2022-01-24T10:17:00",
"IsApproximateTime": false,
"Height": 5.444324680328854,
"IsApproximateHeight": false,
"Filtered": false,
"Date": "2022-01-24T00:00:00"
},
{
"EventType": "LowWater",
"DateTime": "2022-01-24T17:35:00",
"IsApproximateTime": false,
"Height": 0.8888834979599549,
"IsApproximateHeight": false,
"Filtered": false,
"Date": "2022-01-24T00:00:00"
},
{
"EventType": "HighWater",
"DateTime": "2022-01-24T22:38:00",
"IsApproximateTime": false,
"Height": 6.008938731402115,
"IsApproximateHeight": false,
"Filtered": false,
"Date": "2022-01-24T00:00:00"
},
{
"EventType": "LowWater",
"DateTime": "2022-01-25T05:50:00",
"IsApproximateTime": false,
"Height": 0.8994946691625086,
"IsApproximateHeight": false,
"Filtered": false,
"Date": "2022-01-25T00:00:00"
},

Any pointers would be grately appreciated.

Andy