Branden Wagner Posted November 15, 2006 Share Posted November 15, 2006 Ok, so i am making a page for System status updates(generated by my server).... i am having a small problem figuring out the logic...so i have in the mysql db the id,note,author,timestamp. i want everything sorted by day, and then time as far as the html displays iti know i can do a query to "order by timestamp desc" and that puts them into the right order, but doesnt display them the way i want, because i want to break up the individual days. like i have here: [url=http://dev.pureintellect.com/status/index.html]http://dev.pureintellect.com/status/index.html[/url]so how do i do this? any suggestions would be helpful. its not so much the php thats the problem, just the logic atleast i think thats my only problem. Quote Link to comment Share on other sites More sharing options...
btherl Posted November 15, 2006 Share Posted November 15, 2006 You can fetch all the data sorted by timestamp, and then have a loop which extracts the day and time, and then displays according to those values. By keeping the last displayed day in a variable, you will know when to start displaying a new day (it will be whenever the current day is not equal to the last displayed day).[code=php:0]$last_day = null;foreach ($data as $d) { list($day, time) = extract_day_time($d['timestamp']); if ($day !== $last_day) { # New day } else { # Continue current day }}[/code] Quote Link to comment Share on other sites More sharing options...
Branden Wagner Posted November 17, 2006 Author Share Posted November 17, 2006 Thank you....that cleared up the logic error... and worked... but not really... lol its a small problem, i made a minor change, because i hate foreach loops..[code]mysql_connect($db_host,$db_user,$db_pass);mysql_select_db($db_name);$result =mysql_query("SELECT UNIX_TIMESTAMP(date) as date FROM status WHERE resolved=0 ORDER BY date DESC");$data = mysql_fetch_assoc($result);while($row = mysql_fetch_assoc($result)){ $day = $row['date']; echo date("Y/m/j g:i:s",$day) ."<br />";}[/code]i know there are 4 results.. mysql_num_rows confirms ( also checked via sql console).but yet only 3 show up... am i missing something? Quote Link to comment Share on other sites More sharing options...
Branden Wagner Posted November 17, 2006 Author Share Posted November 17, 2006 nevermind i figured it out..$data = mysql_fetch_assoc($result);while($row = mysql_fetch_assoc($result))setting $data then increments the movement of $result resourcesleaving while loop with only 3. 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.