toocreepy Posted January 24, 2011 Share Posted January 24, 2011 I'm pulling a list from a DB and inserting it in a drop down menu. Each item on the list has a numerical id associated called marketid in the DB. It works, but it orders the list alphabetically. I need it to order by marketid which is the column name. What code do I need to add? Here is what I have now.... <option value="<?=$market['marketid']?>"><?=$market['name']?></option> Thanks in advance all!! Tony Quote Link to comment https://forums.phpfreaks.com/topic/225539-order-by-id-not-alphabetical/ Share on other sites More sharing options...
taquitosensei Posted January 24, 2011 Share Posted January 24, 2011 in your sql order by name Quote Link to comment https://forums.phpfreaks.com/topic/225539-order-by-id-not-alphabetical/#findComment-1164578 Share on other sites More sharing options...
toocreepy Posted January 24, 2011 Author Share Posted January 24, 2011 here's all the code for the drop down.... <select name="market[]" size="10" multiple="multiple" id="market[]"> <?php $markets = $crf->GetMarkets (); foreach ($markets as $market) { ?> <option value="<?=$market['marketid']?>"><?=$market['name']?></option> <?php } ?> </select> Quote Link to comment https://forums.phpfreaks.com/topic/225539-order-by-id-not-alphabetical/#findComment-1164582 Share on other sites More sharing options...
mikecampbell Posted January 24, 2011 Share Posted January 24, 2011 If you can modify the $crf->GetMarkets() method that would be preferable. Change it to add the SQL sort that taquitosensei suggested. Otherwise, it gets a bit messy sorting a multidimensional array. You could try copying this function into your code: http://www.exorithm.com/algorithm/view/sort_multi_array Call it just before your foreach statement and pass $markets as the first parameter and 'name' as the second. Quote Link to comment https://forums.phpfreaks.com/topic/225539-order-by-id-not-alphabetical/#findComment-1164587 Share on other sites More sharing options...
toocreepy Posted January 24, 2011 Author Share Posted January 24, 2011 modifying Getmarkets worked. Thanks!!!! Quote Link to comment https://forums.phpfreaks.com/topic/225539-order-by-id-not-alphabetical/#findComment-1164597 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.