I have a while loop of sql entries ordered by a date added descending. There is a second date column named activated, when each entry is activated (just a click on the entry).
Once all entries are displayed and ordered by date I want add special style to the one entry with the latest activated date, which is not equal to the date of adding. All other entries would be without special styling.
Does anyone know for a simple php date solution to pin out the entry with latest activated date?
There is a way to do that in mysql allready:
SELECT <your other stuff>, (IF(activated_date = (SELECT MAX(activated_date) FROM your_TABLE WHERE activated_date != added_date ), 1,0)) as last_entrie FROM your_table <your ORDER BY stuff>
With this the row with the highest activated_date
which is not the same as the added_date
will have a 1 as last_entrie
, while the rest has a 0. You can then use that information to highlight the row in PHP.
I haven't tried a PHP solution, but with this you don't need to go through all the data in PHP to find the highest entrie, that fullfills your needs.