Ok! I have worked it out, with help from @Sean and my Auntie Lou :D. I am sure there is an easier way to do it though.
I have decided to create a new table and copy the information needed into it and generate new id's. As I am only working on a small database I am not worried about overheads.
Firstly CREATE
a new table
(temp_gaps
), then SELECT
the required information from the original table
(placements
) excluding the id
column. This copies the data from the original table to the new one without ID's. The new table generates a new auto_increment
ID so everything is now in order in the new table:
CREATE TABLE temp_gaps
(
`id` mediumint(6) NOT NULL auto_increment,
`date` date NOT NULL,
`stime` time NOT NULL,
`etime` time NOT NULL,
`staff` varchar(50) NOT NULL,
`client` varchar(50) NOT NULL,
PRIMARY KEY (`id`)
)
engine=memory AS
(SELECT date,stime,etime,staff,client
FROM placements
ORDER BY `staff`,`date`,`stime` ASC)
Once the information is copied I can then use @Sean previous answer to pull the information, left_join
the etime
column and I can then work on the data result in my PHP script. Once i'm done I just drop
the table and all is good.
Thanks to Sean for sending me in exactly the right direction.