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 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 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> 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. 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!!!! 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
Archived
This topic is now archived and is closed to further replies.