| Posted by J.O. Aho on 12/19/06 13:45 
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.
 
 Why not make a table with the following:
 
 table MiscStuff
 MSID INT
 MSName
 
 and you store things like
 
 0 Snow
 1 Winter
 
 You store the values into the database, when you fetch you just join the
 MiscStuff table with the table where you store the data, this way you get the
 text out of the database.
 
 
 > So i can make something like this:
 > if (options = "0" )
 >     options = "Snow";
 > write options into db.
 
 You better do it like this:
 switch($_REQUEST['options']) {
 case 0:
 $options = "Snow";
 break;
 case 1:
 $options = "Winter";
 break;
 default:
 /* Value was selected that isn't listed before this line */
 $options = "Stupid user";
 break;
 }
 
 Or why not just
 
 <select name="options">
 <option>Snow</option>
 <option>Winter</option>
 </select>
 
 
 --
 
 //Aho
 [Back to original message] |