Forum Moderators: coopster

Message Too Old, No Replies

multiple selection count

         

Artvido

8:21 pm on Apr 12, 2005 (gmt 0)

10+ Year Member



I'm fairly new to php and I can't figure this problem out:

I have a multiple selection list/menu with list of states. User holds Ctrl key and selects desired states.

Once states are selected user hits submit and all selected states are passed through post variable to the next page.

That part is all fine, selected states are passed and it works.

What I would like to also be able to do is get the number of all states selected.

For example: when <? I echo $states;?>
I get list of all selected states.

Is there a command or a way to retrieve number of states selected? for example if user selected 4 states (Alabama, New York, Texas, Florida) in addition to the list I would also like to get the total number of selected states. In this case the number would be 4. This could be assigned to a new variable for example:

<? $TotalStatesSelected?>

I hope this make sense... Does anyone know how to achieve this?

Thank you
Dariusz

sned

8:57 pm on Apr 12, 2005 (gmt 0)

10+ Year Member



Hi Dariusz, I know for sure there's at least one thing you can do. If your multiple select is set up something like:

<select name="whatever[]" .... that will pass an array.

In the processing page, $states would hold the array.

count($states) would give you the number selected. You can then loop through the array to do whatever else you need. Hope that helps.

-sned

Artvido

9:54 pm on Apr 12, 2005 (gmt 0)

10+ Year Member



sned,

Thanks a lot! that's it. I had this variable all the time, I just did not think to echo it.

Simple things can make us so happy :)

Thanks again for pointing me in the right direction.

Dariusz

coopster

10:06 pm on Apr 12, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Nice work sned and welcome to WebmasterWorld Artvido.