There is another way -- I sometimes do this...

you can have both the id and text in the value like so...

<option value="1--product1">Product 1
<option value="2--another product">Another product

then parse through the value list and split it on "--"

foreach ($listOfProducts as $prod){
        if (!$prod){break;}
        list ($productID,$productName) = split("--",$prod);


-----Original Message-----
From: John W. Holmes [mailto:[EMAIL PROTECTED]] 
Sent: Thursday, October 03, 2002 7:57 PM
To: 'Hutchins, Richard'; [EMAIL PROTECTED]
Subject: RE: [PHP-DB] Pulling apart select list elements

> I have a <select multiple></select> object named list[] that is
> its
> selected contents to an array. That part works fine. I can use a for
> to
> grab all of the selected items. Where I'm stuck is that I want to get
> the value AND the text for any given <option> element and simply
> the items in the array 1-N based on the number of rows is not
> Example:
> <select name="itemList[]" multiple>
>       <option value="101">PHP For Dummies</option>
>       <option value="102">PHP For Professionals</option>
>       <option value="103">PHP For Gurus</option>
> </select>
> I want to be able to be able to get both the value property (101, 102,
> ...)
> AND the text between the <option></option> tags. Currently, I'm only 
> getting the text between the <option></option> tags. Is there a PHP 
> function
> allows me to get to both?

No, you only get the value="" part. I think your confused, or this isn't the
correct code, when you say your are getting what's between <option></option>
then you're doing something different.

Bottom line, you only get the value part. If you want two values passed,
then use some hidden elements to relate the values.

<input type="hidden" name="itemListtext[101]" value="PHP For Dummies">

would relate to your first element. So in PHP, you'd have

$_POST['itemList'][0] == 101
$_POST['itemListtext'][$_GET['itemList'][0]] == "PHP For Dummies"

If you're using your database correctly, all you should need is the number,

---John Holmes...

PHP Database Mailing List (
To unsubscribe, visit:

Reply via email to