richr Posted September 20, 2011 Share Posted September 20, 2011 Hello, I'm just learning php (by force), but am pretty well versed in html and css. I did not rite the following code and I'm not sure how to pull out the php in the following in order to make the page validate. <tr> <td width="15%"><b><b>Priority</b></td> <td> <select name="priority" size="1" value="priority"> <option value="" <?php if ($row['priority'] == "") echo " selected";?> ></option> <option value="Normal" <?php if ($row['priority'] == "Normal") echo " selected";?> >Normal</option> <option value="Elevated" <?php if ($row['priority'] == "Elevated") echo " selected";?> >Elevated</option> <option value="STAT" <?php if ($row['priority'] == "STAT") echo " selected";?> >STAT</option> </select> </td> </tr> The idea is to prefetch the "priority" info and populate the drop down with that. Afterwards, the user can change the value and once submitted, the value will change in the database. Any pointers would be appreciated - and thanks in advance. Rich Quote Link to comment https://forums.phpfreaks.com/topic/247512-php-in-selectoptions/ Share on other sites More sharing options...
Muddy_Funster Posted September 20, 2011 Share Posted September 20, 2011 is that from within a WHILE loop? Quote Link to comment https://forums.phpfreaks.com/topic/247512-php-in-selectoptions/#findComment-1271003 Share on other sites More sharing options...
richr Posted September 20, 2011 Author Share Posted September 20, 2011 yes, I believe so Quote Link to comment https://forums.phpfreaks.com/topic/247512-php-in-selectoptions/#findComment-1271010 Share on other sites More sharing options...
WebStyles Posted September 20, 2011 Share Posted September 20, 2011 you could do something like this: <?php $priorityList = array("","Normal","Elevated","STAT"); echo '<select name="priority" size="1" value="priority">'; foreach($priorityList as $p){ echo '<option value="'. $p .'"'; if($row['priority'] == $p) echo ' selected'; echo '></option>'; } echo '</select>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/247512-php-in-selectoptions/#findComment-1271012 Share on other sites More sharing options...
Muddy_Funster Posted September 20, 2011 Share Posted September 20, 2011 The only issue I can see that could apply to validation is, that as far as I know, you should be echoing 'selected="selected"' rather than just echoing 'selected'. Quote Link to comment https://forums.phpfreaks.com/topic/247512-php-in-selectoptions/#findComment-1271033 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.