Jump to content

Order by ID, not alphabetical


toocreepy

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.