ethar Posted June 4, 2013 Share Posted June 4, 2013 I'm trying to output a list of different itmes grouped by the date they were stored in the databaseI'd need help with both MySQL (query) and PHP (output).MySQL tableid | subject | time1 | test1 | 12802788002 | test2 | 12802788003 | test3 | 12803652004 | test4 | 12804516005 | test5 | 1280451600OUTPUTTodaytest5test4Yesterdaytest3July 28test2test1I'd appreciate any help on this. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/278782-mysql-php-grouping-by-date/ Share on other sites More sharing options...
requinix Posted June 5, 2013 Share Posted June 5, 2013 (edited) Sort by the time descending and change your headings in code when the corresponding date changes. $date = empty foreach ($row found) { if (date from $row != $date) { $date = date from $row echo new date heading } echo item }If your dates are grouped using something that needs beginning and ending output (like a beginning and ending ) then use a slightly more complicated $date = empty foreach ($row found) { if (date from $row != $date) { if ($date is not empty) { echo ending output } $date = date from $row echo new date heading and beginning output } echo item } if ($date is not empty) { echo ending output } Edited June 5, 2013 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/278782-mysql-php-grouping-by-date/#findComment-1434148 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.