Jump to content

Populating a Drop down field


Jon12345

Recommended Posts

I have a drop down field on edit.php, which lets me edit a list of data for one record. The status field has 3 values: Not Started, Pending, or Finished.

I've been trying to get this to work:

[code]<? if ($row['review']="Not Started") { echo "<option selected>"; } else {echo "<option>"; } ?>Not Started</option>
<? if ($row['review']="Pending") { echo "<option selected>"; } else {echo "<option>"; } ?>Pending</option>[/code]

Any suggestions on what best practice is in this area?

Thanks,

Jon
Link to comment
https://forums.phpfreaks.com/topic/30414-populating-a-drop-down-field/
Share on other sites

You need to use double equal signs in if statements - unless you are trying to assing a value. Here is another approach:

[code]
<?php
echo "<option" . (($row['review']=="Not Started")?" selected":"") . ">Not Started</option>";
echo "<option" . (($row['review']=="Pending")?" selected":"") . ">Pending</option>";
?>
[/code]
How about this

[code=php:0]<option <? if($row['review'] == "Not Started"){ echo "selected";}?>>Not Started
<option <? if($row['review'] == "Selected"){ echo "selected";}?>>Selected[/code]

The main problem with your original script was you had only a single = not == in your if statement

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.