gc40 Posted August 21, 2007 Share Posted August 21, 2007 I am trying to write a function for an update script I am doing. Currently, there is a table called Category which contains a numeric value of 1-3. The Category is displayed as text output thanks to an array and or if statement. If Category = 1, then Output = Test 1 If Category = 2, then Output = Test 2 If Category = 3, then Output = Test 3 Here is what my code currently looks like: <td><select name='Category'> <? $s_array = array('Test 1','Test 2','Test 3')?> <option SELECT value='<? if(array_key_exists($onenav->Category, $s_array)) {?><?php echo($onenav->Category);?>'><? echo $s_array[$onenav->Category] ;?><? } ?></option> <option value='1'> Test 1 </option> <option value='2'> Test 2 </option> <option value='3'> Test 3 </option> </select> <br /> </td> You will notice that the array exist and SHOULD list the Category name if the number matches the array, however, it does not. Also, you will notice that the Test 1, Test 2 and Test 3 are listed as select <option> tags. This is because when a user is updating the page, if the current Category is Test 1, and he wishes to update to Test 2, then he can. However, I would like it so that NO Category is repeated twice. If there anything I can do to allow me to have the option selected if it exist? and also, how do I get that array working to list the Category as Text output selecting the option that matches the current database value. Quote Link to comment https://forums.phpfreaks.com/topic/65939-solved-select-option-and-database-query/ Share on other sites More sharing options...
vijayfreaks Posted August 21, 2007 Share Posted August 21, 2007 Hi.. you can get that via this also.. <option value='1' <?php if($onenav->Category == "test1") { echo "selected"; } ?>> Test 1 </option> <option value='2' <?php if($onenav->Category == "test2") { echo "selected"; } ?>> Test 2 </option> <option value='3' <?php if($onenav->Category == "test3") { echo "selected"; } ?>> Test 3 </option> suppose this would help you. Regards, Vijay Quote Link to comment https://forums.phpfreaks.com/topic/65939-solved-select-option-and-database-query/#findComment-329716 Share on other sites More sharing options...
gc40 Posted August 21, 2007 Author Share Posted August 21, 2007 Thank yoU! Quote Link to comment https://forums.phpfreaks.com/topic/65939-solved-select-option-and-database-query/#findComment-329717 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.