Jump to content

Sorting Values in a Combo box.


theITvideos

Recommended Posts

Hi there,

 

I am working on a PHP web form and I have a combo box and I'm trying to sort the values in it.

 

The values in the combo box are filled using an arraylist:

 

$WeightArray = array('' => '',
    '0|100' => '100g or Less',
    '101|250' => '101g to 250g', 
    '251|500' => '251g to 500g',
    '501|1000' => '501g to 1kg',
    '1000|2000' => '1kg to 2kg',
    '2000|3000' => '2kg to 3kg',
    '3000|4000' => '3kg to 4kg',
    '4000|5000' => '4kg to 5kg',
    '5000|6000' => '5kg to 6kg',
    '6000|7000' => '6kg to 7kg',
    '7000|8000' => '7kg to 8kg', 
    '8000|9000' => '8kg to 9kg',  
    '9000|10000' => '9kg to 10kg',
    'customValues' => 'Custom Values'
    );

 

The values get properly filled in the combo box. Thats fine. Its just that the values are not sorted the way I want them to. The Grams and Kilograms are all mixed. It should output in the order defined in the array.

 

See the ScreenShot I've taken and see the difference in the values defined and the output.

 

I tried few sorting methods like

 

ksort($WeightArray);

But still the same output.

 

Whats the good trick to sort values in Combo as per the array.

 

All comments and feedback are always welcomed. :)

 

Thank you.

 

 

[attachment deleted by admin]

Link to comment
Share on other sites

Now how do we iterate the values.

 

You have got to be kidding... You are already iterating over the values. Just remove the sort function.

 

I've removed the sort function. And it didn't sort.

 

And the way the code is written by ex-programmers is completely different from regular code.

 

There is no regular combo box defined. The way the Arraylist values is called into a combo box is:

 

 

 'ShipmentWeight' => array('type' => 'select', 'label' => 'Shipment Weight:', 'options' => $WeightArray)

 

There is a whole list of arrays, just a mesh of arrays in the code.

 

There is no regular:

 

<select name="ComboName">
.
.
.
</select>

 

I probably cannot use the regular looping here. I just need to sort the arraylist values of  i.e  $WeightArray.

 

What do you suggest after looking at some bits of my code.

 

Cheers! :)

 

Link to comment
Share on other sites

The way the Arraylist values is called into a combo box is: ...

 

Again, you cannot be serious.

 

You have got a specific data definition that you didn't bother to share and some specific code that is processing that and you somehow want help with how it is sorting without showing anyone here that information?

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.