Eiolon Posted October 16, 2008 Share Posted October 16, 2008 I have a dynamic drop down menu that is pull categories from a database. I have everything listed in alphabetical order however, I want one item to always be listed as the first thing in the box even though its not at the beginning of the alphabet. $query_categories = "SELECT * FROM categories ORDER BY category ASC"; $categories = mysql_query($query_categories) OR die ('Cannot retrieve a list of categories.'); <select name="category" id="category" style="width:250px"> <?php while($row_categories = mysql_fetch_array($categories)) { print '<option value="' . $row_categories['category_id'] . '">' . $row_categories['category'] . '</option>'; } ?> </select> That's the code I have now. Not sure what to do about the moving of the item to the top. Thanks for your help! Quote Link to comment https://forums.phpfreaks.com/topic/128757-solved-dynamic-drop-down-menu-but-with-an-item-always-listed-first/ Share on other sites More sharing options...
Barand Posted October 16, 2008 Share Posted October 16, 2008 Let us suppose that category with id = 5 should always be first, and the rest in alphabetical order SELECT * FROM categories ORDER BY category_id=5 DESC, category ASC Quote Link to comment https://forums.phpfreaks.com/topic/128757-solved-dynamic-drop-down-menu-but-with-an-item-always-listed-first/#findComment-667360 Share on other sites More sharing options...
Eiolon Posted October 16, 2008 Author Share Posted October 16, 2008 Wow, that was easy. Works fine. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/128757-solved-dynamic-drop-down-menu-but-with-an-item-always-listed-first/#findComment-667369 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.