I need help on how to get/display some informations from DB (MySQl)
My current table looks like this:
id | title | level | start_afterID | days |
1 | A | 0 | 0 | 7 |
2 | B | 1 | 1 | 5 |
3 | C | 1 | 2 | 3 |
4 | D | 1 | 3 | 2 |
5 | E | 1 | 4 | 2 |
6 | F | 1 | 3 | 6 |
Level ‘0’ means that this job will start first and start day and time is in other table ($config_start)
All others entry with level = 1 don’t have fixed start, just id of job (start_afterID) after which they start.
Also every job will last in number of days from DAYS field.
In this table job with ID 6 (title F) must start after jobID 3 – And that start time is something like:
$config_start + jobID 3 + jobID 2;
$end of this job is:
$config_start + jobID 3 + jobID 2 + 6;
At the end, I will need to display all jobs from DB in incoming order.
I tried my best with this, but i can’t figure how to check all parent levels and calculate it.
Also, I can create new administration for this and maybe there is a better way of inserting new jobs ?
THANKS for any help on this,
First of all, I advise you to rethink the
levelcolumn – IIUC this is only a boolea, telling you wether this is a job root or not – this information is also prsent in start_afterID being 0.Now calculating the start and end times is a non-trivial job, that requires lots of DB avvess, so I advise you to create a second table with
id|startday|enddayand move the calculation logic in a way, that this (essentially cache) table is updated on job change, leaving you with a fast query path for normal operations.To calculate the contents of this timing table, you would do something like