cordoprod Posted May 25, 2008 Share Posted May 25, 2008 Hi. I have an action log with mysql where i want to sort the rows in days.. Like this: Sunday 25th of May 2008 -- rows Saturday 24th of May 2008 -- rows From a timestamp from time() btw.. Link to comment https://forums.phpfreaks.com/topic/107230-split-into-day/ Share on other sites More sharing options...
BlueSkyIS Posted May 25, 2008 Share Posted May 25, 2008 select all records, including the timestamp as a date, group by that date and sort by that date DESCENDING, then loop over the results, keeping track of the current date. when the date changes, add a new row with 'Sunday 25th of May 2008', then continue displaying records. Link to comment https://forums.phpfreaks.com/topic/107230-split-into-day/#findComment-549760 Share on other sites More sharing options...
cordoprod Posted May 25, 2008 Author Share Posted May 25, 2008 Could you show some code? Link to comment https://forums.phpfreaks.com/topic/107230-split-into-day/#findComment-549762 Share on other sites More sharing options...
AndyB Posted May 25, 2008 Share Posted May 25, 2008 Could you show some code? We don't know your database field names, etc. Show us your efforts first, then we'll help. Link to comment https://forums.phpfreaks.com/topic/107230-split-into-day/#findComment-549767 Share on other sites More sharing options...
cordoprod Posted May 25, 2008 Author Share Posted May 25, 2008 Sorry. The structure is of the table travek_logg: nick | time | action Link to comment https://forums.phpfreaks.com/topic/107230-split-into-day/#findComment-549768 Share on other sites More sharing options...
BlueSkyIS Posted May 25, 2008 Share Posted May 25, 2008 Show us your efforts first, then we'll help. Link to comment https://forums.phpfreaks.com/topic/107230-split-into-day/#findComment-549770 Share on other sites More sharing options...
cordoprod Posted May 25, 2008 Author Share Posted May 25, 2008 Yeah, that's the problem... I don't know what query to use Link to comment https://forums.phpfreaks.com/topic/107230-split-into-day/#findComment-549773 Share on other sites More sharing options...
BlueSkyIS Posted May 25, 2008 Share Posted May 25, 2008 what have you got so far? what does the output look like? if you have nothing, you've got to try something. Link to comment https://forums.phpfreaks.com/topic/107230-split-into-day/#findComment-549775 Share on other sites More sharing options...
cordoprod Posted May 25, 2008 Author Share Posted May 25, 2008 <? $db = new DbConnector(); $db->connect(); $sql = "SELECT * FROM travek_logg GROUP BY time SORT BY time DESC"; $result = $db->query($sql); while($fetch = mysql_fetch_array($result)) { } ?> Now i don't have a clue... and am pretty sure the query is wrong.. Link to comment https://forums.phpfreaks.com/topic/107230-split-into-day/#findComment-549780 Share on other sites More sharing options...
cordoprod Posted May 25, 2008 Author Share Posted May 25, 2008 <? $db = new DbConnector(); $db->connect(); $sql = "SELECT * FROM travek_logg GROUP BY time ORDER BY time DESC"; $result = $db->query($sql); $day = "yes"; while($fetch = mysql_fetch_array($result)) { if($day != "no") date("l", $fetch['time']); echo "<br>".$fetch['nick']; $day = "no"; } ?> The output will be: glenn heihei - No day... Link to comment https://forums.phpfreaks.com/topic/107230-split-into-day/#findComment-549796 Share on other sites More sharing options...
cordoprod Posted May 26, 2008 Author Share Posted May 26, 2008 I saw that i forgot the echo.... But when i have the echo the output will be: Sunday -- rows But, when it changes day what should i do? Link to comment https://forums.phpfreaks.com/topic/107230-split-into-day/#findComment-550155 Share on other sites More sharing options...
cordoprod Posted May 26, 2008 Author Share Posted May 26, 2008 Any ideas? Link to comment https://forums.phpfreaks.com/topic/107230-split-into-day/#findComment-550193 Share on other sites More sharing options...
BlueSkyIS Posted May 26, 2008 Share Posted May 26, 2008 But, when it changes day what should i do? echo the new day and continue? Link to comment https://forums.phpfreaks.com/topic/107230-split-into-day/#findComment-550195 Share on other sites More sharing options...
cordoprod Posted May 26, 2008 Author Share Posted May 26, 2008 yeah how? Like this? <? $db = new DbConnector(); $db->connect(); $sql = "SELECT * FROM travek_logg GROUP BY time ORDER BY time DESC"; $result = $db->query($sql); $day = "yes"; while($fetch = mysql_fetch_array($result)) { if($day != "no" && $day2 != date("l", $fetch['time'])) echo date("l", $fetch['time']); echo "<br>".$fetch['nick']; $day = "no"; $day2 = date("l", $fetch['time']); } ?> Link to comment https://forums.phpfreaks.com/topic/107230-split-into-day/#findComment-550206 Share on other sites More sharing options...
cordoprod Posted May 26, 2008 Author Share Posted May 26, 2008 Do you know whats wrong? Cause it only outputs one day..... Link to comment https://forums.phpfreaks.com/topic/107230-split-into-day/#findComment-550316 Share on other sites More sharing options...
cordoprod Posted May 27, 2008 Author Share Posted May 27, 2008 Any ideas? Link to comment https://forums.phpfreaks.com/topic/107230-split-into-day/#findComment-550722 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.