Jump to content

php in select>options


richr

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/247512-php-in-selectoptions/
Share on other sites

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>';
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.