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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.