BrandonE97 Posted August 1, 2007 Share Posted August 1, 2007 I have multiple dates the same in my database but I only need each date shown once. If I have two entried under july7 then it shows july7 two times on my page. Is there a way to only show each date once? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/62897-multiple-dates/ Share on other sites More sharing options...
Barand Posted August 1, 2007 Share Posted August 1, 2007 Yes, but the method would depend on the context in which you want to show the date once. Some code would be useful. Quote Link to comment https://forums.phpfreaks.com/topic/62897-multiple-dates/#findComment-313109 Share on other sites More sharing options...
akitchin Posted August 1, 2007 Share Posted August 1, 2007 this is a matter of keeping a running tab on what date you're currently on, and only echoing it if it's different from the last: while ($stuff = stuff) { // echo this row's value if it differs from the last value if ($last_loop_val != $stuff['this_loop_val']) { echo 'new value: '.$stuff['this_loop_val']; } // do your stuff here // assign the last value to this value for the next loop $last_loop_val = $stuff['this_loop_val']; } EDIT: you and your speedy typing, barand. Quote Link to comment https://forums.phpfreaks.com/topic/62897-multiple-dates/#findComment-313111 Share on other sites More sharing options...
BrandonE97 Posted August 1, 2007 Author Share Posted August 1, 2007 Okay, that works great but also is there a way to keep the months in a certain order. Kind of like ORDER BY but in a specific order? Quote Link to comment https://forums.phpfreaks.com/topic/62897-multiple-dates/#findComment-313115 Share on other sites More sharing options...
Barand Posted August 1, 2007 Share Posted August 1, 2007 My reply was a bit shorter - I wasn't sure if he was doing something like that or if SELECT DISTINCT would suffice. Quote Link to comment https://forums.phpfreaks.com/topic/62897-multiple-dates/#findComment-313117 Share on other sites More sharing options...
akitchin Posted August 1, 2007 Share Posted August 1, 2007 you'd have to translate your month into its ordered value, and order on that: SELECT stuff, (CASE DATE_FORMAT(row_date, 'something') WHEN something THEN 1, WHEN something_else THEN 2, WHEN something_even_elser THEN 3) AS order_key ORDER BY order_key ASC what you use in DATE_FORMAT() depends on in what way you want to assign orders. if it's month, you'll probably want to use %b or %c. see the manual for the differences. don't know if this is the most efficient way, so i'm hoping an SQL guy comes around and suggests a better way (or validates this one). Quote Link to comment https://forums.phpfreaks.com/topic/62897-multiple-dates/#findComment-313119 Share on other sites More sharing options...
BrandonE97 Posted August 1, 2007 Author Share Posted August 1, 2007 Thanks guys for your help. I'll be trying this code tomorrow when I get back home lol. Many Thanks (Im still learning a lot of this stuff) Quote Link to comment https://forums.phpfreaks.com/topic/62897-multiple-dates/#findComment-313120 Share on other sites More sharing options...
Barand Posted August 1, 2007 Share Posted August 1, 2007 If you want to treat the the year and date as separate fields you can SELECT YEAR(row_date) as yr, MONTHNAME(row_date) as mname, .... Quote Link to comment https://forums.phpfreaks.com/topic/62897-multiple-dates/#findComment-313135 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.