Makke_ Posted April 2, 2013 Share Posted April 2, 2013 (edited) Hi,I am trying to display week number in a drop down menu.I managed to display the numbers but not distinct.I´ve tried using array_unique but i´m not sure how to implement it. (below code shows how I tried to use array_unique. $sql="SELECT Date FROM maildata ORDER BY Date ASC"; $result = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_array($result)){ $date_string = date($row['Date']); $week = array_unique($date_string); $options .="<option>". date("W", strtotime($week))."</option>"; ?> <SELECT name="week"> <OPTION VALUE="">Choose week <?=$options?> </SELECT> Edited April 2, 2013 by Makke_ Quote Link to comment https://forums.phpfreaks.com/topic/276430-display-unique-values/ Share on other sites More sharing options...
DavidAM Posted April 2, 2013 Share Posted April 2, 2013 Since $date_string is not an array, that code should report an error. To use array_unique() you would need to collect all of the week numbers in an array, then call it against that array. On the other hand, you should select DISTINCT dates so you don't process the same date multiple times. In fact, you could do the week number and distinct in the query (mySql WEEK): SELECT DISTINCT WEEK(Date) AS WeekNo FROM maildata ORDER BY 1 ASC Quote Link to comment https://forums.phpfreaks.com/topic/276430-display-unique-values/#findComment-1422446 Share on other sites More sharing options...
Makke_ Posted April 2, 2013 Author Share Posted April 2, 2013 Thanks for a quick reply.It did work but it starts to count from 0. Quote Link to comment https://forums.phpfreaks.com/topic/276430-display-unique-values/#findComment-1422450 Share on other sites More sharing options...
Solution Makke_ Posted April 3, 2013 Author Solution Share Posted April 3, 2013 I did like this and then i seems to work!Thanks for your help! SELECT DISTINCT WEEK(Date, 1) AS WeekNo FROM maildata ORDER BY 1 ASC Quote Link to comment https://forums.phpfreaks.com/topic/276430-display-unique-values/#findComment-1422585 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.