networkthis Posted November 8, 2008 Share Posted November 8, 2008 I am trying to populate a drop menu from mysql...I would like to not have locations that have already displayed to be redisplayed. There are a lot of duplicated locations. Each location only needs to be displayed one time in the menu. I have a seperate search function written to display mysql results based on selected location. Any ideas or suggestions would be great! Thanks in advance <?php $query="SELECT location FROM jb"; $result = mysql_query ($query);echo "<select name=category value=''></option>"; while($nt=mysql_fetch_array($result)){ echo "<option value=$nt[location]>$nt[location]</option>"; }echo "</select>"; ?> Link to comment https://forums.phpfreaks.com/topic/131878-drop-menu/ Share on other sites More sharing options...
Jeremysr Posted November 8, 2008 Share Posted November 8, 2008 It sounds like changing your MySQL query to only select "distinct" locations is what you want: $query="SELECT DISTINCT location FROM jb"; This will not give you any duplicate location fields. Link to comment https://forums.phpfreaks.com/topic/131878-drop-menu/#findComment-685114 Share on other sites More sharing options...
networkthis Posted November 8, 2008 Author Share Posted November 8, 2008 awesome thank you so much!!! Now that brings up another question... where is there a good source for all of the different things you can do with mysql querys and some examples for the mysql querys??? Also how difficult is it to sort these alphabetically? Link to comment https://forums.phpfreaks.com/topic/131878-drop-menu/#findComment-685118 Share on other sites More sharing options...
networkthis Posted November 8, 2008 Author Share Posted November 8, 2008 OK I actually knew the answer for the sorting, just forgot!!! Is this the most efficient way though? <?php $query="SELECT DISTINCT country FROM jb_jobs ORDER BY country ASC"; ?> Link to comment https://forums.phpfreaks.com/topic/131878-drop-menu/#findComment-685119 Share on other sites More sharing options...
Jeremysr Posted November 8, 2008 Share Posted November 8, 2008 awesome thank you so much!!! Now that brings up another question... where is there a good source for all of the different things you can do with mysql querys and some examples for the mysql querys??? Google it: http://google.com/search?q=mysql+tutorials You'll find all sorts of tutorials and documentation for MySQL. OK I actually knew the answer for the sorting, just forgot!!! Is this the most efficient way though? Yep, it is. Link to comment https://forums.phpfreaks.com/topic/131878-drop-menu/#findComment-685122 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.