|
Posted by Tom on 12/19/06 19:19
On 19 Dec 2006 07:14:08 -0800, Moot wrote...
>
>Joja wrote:
>> Hi !
>>
>> Maybe i have described this on the wrong way....
>>
>> This is what im passing after you click update button:
>>
>> <select name="options">
>> <option value="0" >Snow </option>
>> <option value="1" >Winter</option>
>> </select>
>>
>> If i write this to db then i will write "0" or "1" and i want to store
>> "Snow" or "Winter" into db.
>> I have to use numerical values for my other use with select, but i must
>> store text into db.
>>
>
>Ah, I see the problem now.
>
>You have a few possible solutions, then. Firstly: where are you
>getting the data for the 0-snow, 1-winter options? Is this coming from
>a database, or hardcoded? If it is coming from a database, then with
>the value you could probably query for the name.
>
>If not, then you should understand that the only data that is passed to
>the script is whatever is in value="". PHP could care less as to what
>text is displayed to the user. I would probably get around this by
>putting both values that I want into the value attribute and then
>parsing them out in PHP. For example:
>
><select name="options">
> <option value="0||Snow" >Snow </option>
> <option value="1||Winter" >Winter</option>
></select>
>
>Then, while processing the form:
>$optionsData = explode("||",$_POST['options']);
>//at this point, $optionsData[0] = '0', $optionsData[1] = 'Snow', and
>you can now use both values
>
>- Moot
>
Thanks a good idea. That way you can keep the numberic value and the text
together and save an extra SQL query later.
Tom
--
Newsguy.com - Express Accounts - 30 GB $9.95 / month
Navigation:
[Reply to this message]
|