It seems to be nothing complicated, just the brain is already boiling (

There are 3 dates. For each you need to choose a specific color:

  • Red if it has not come yet.
  • Orange if it has not come yet, BUT and the previous one has not come (that is, it goes next).
  • Green if already passed.

Those. Need a function that will receive 3 dates as input. or 2. Ie I can't come up with the correct function architecture. It should return only color. And it will be called 3 times. Not for 1 time produces colors, but 3 times. Dates can be 2.

What is it for? For X stages set time. For example, the first is 12/04/2012, the second is 13/04/2012, the third is 04/14/2012

Now - 04/07/2012. So now is the first stage. It will end on 12.04 and then the second stage will begin.

Here you need to visually display.

  • Dates arbitrary or ordered? - FLK
  • Ordered. When added to the database, it is checked that the second date is not earlier than the first. that is, the second stage cannot start earlier than the first. and so on - lnart
  • It seems to me that in your situation it will be easier to check for all necessary conditions in the function, and return an array with colors. Or if there is a direct need to use global variables, or a class. - FLK
  • I know ... but how can I transfer data to it? For example: get_color (date1, date2, date3); // for the first date get_color (date1, date2, date3); // for the second date, since dates go not in a row, but in different tables, ie, calls of these functions are separated by 50-300 lines of code. maybe just 1 call - lnart
  • Those. the function should be universal. Or simply transfer the following data when calling: for the first date get_color(time(),date1,date2) , for the third get_color(date2,date3,time()) . - lnart

1 answer 1

There is some confusion in the question, it is difficult to figure out. But I imagine that there are some DBs 'project' in which there are exactly fields id- key of the stage in the base number - real stage number name - stage name date - stage start date

We write the following query to the database

 SELECT project . * , t.number, t.number - project.number FROM `project` , ( SELECT number FROM `project` WHERE date <= CURDATE( ) ORDER BY number DESC LIMIT 1 ) AS t WHERE ABS( t.number - project.number ) <5 //число 5 - сколько этапов покажем до и после текущего ORDER BY project.number 

So in the result of the query on the field t.number - project.number, you can determine which stage it is:

if> 0 green - already passed

if = 0 - current

if = -1, then the next one is red

if> = - 2 then orange

  • No. A bit wrong .... The database has just 3 date fields. Stage always 3 maximum. This is determined by legislation in this field. There, a cat needs some kind of function that will get 4 arguments like this: get_color ($ date1, $ date2, $ date3, $ etap) Date 3 can be empty, then stage 2. And here, see if we need the color of stage 2 ($ etap = 2) then it checks the date2 with the current time, the previous one. If the stage = 1, then it returns the color with the current time. So probably I will do it ... Only 3 conditions in the function will turn out - lnart