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.. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
cordoprod Posted May 25, 2008 Author Share Posted May 25, 2008 Could you show some code? Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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.. Quote Link to comment 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... Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
cordoprod Posted May 26, 2008 Author Share Posted May 26, 2008 Any ideas? Quote Link to comment 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? Quote Link to comment 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']); } ?> Quote Link to comment 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..... Quote Link to comment Share on other sites More sharing options...
cordoprod Posted May 27, 2008 Author Share Posted May 27, 2008 Any ideas? Quote Link to comment 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.