Jon12345 Posted December 12, 2006 Share Posted December 12, 2006 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 More sharing options...
Psycho Posted December 12, 2006 Share Posted December 12, 2006 You need to use double equal signs in if statements - unless you are trying to assing a value. Here is another approach:[code]<?phpecho "<option" . (($row['review']=="Not Started")?" selected":"") . ">Not Started</option>";echo "<option" . (($row['review']=="Pending")?" selected":"") . ">Pending</option>";?>[/code] Link to comment https://forums.phpfreaks.com/topic/30414-populating-a-drop-down-field/#findComment-139990 Share on other sites More sharing options...
Jon12345 Posted December 12, 2006 Author Share Posted December 12, 2006 Oh that is nicely efficient. Thank you! Link to comment https://forums.phpfreaks.com/topic/30414-populating-a-drop-down-field/#findComment-139992 Share on other sites More sharing options...
Jon12345 Posted December 12, 2006 Author Share Posted December 12, 2006 Actually, that doesn't seem to be working. Now I see no values in the drop down box. Is it a syntax thing? Link to comment https://forums.phpfreaks.com/topic/30414-populating-a-drop-down-field/#findComment-139994 Share on other sites More sharing options...
sanfly Posted December 12, 2006 Share Posted December 12, 2006 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 Link to comment https://forums.phpfreaks.com/topic/30414-populating-a-drop-down-field/#findComment-140003 Share on other sites More sharing options...
Jon12345 Posted December 13, 2006 Author Share Posted December 13, 2006 That did the trick. Thank you. Link to comment https://forums.phpfreaks.com/topic/30414-populating-a-drop-down-field/#findComment-140016 Share on other sites More sharing options...
sanfly Posted December 13, 2006 Share Posted December 13, 2006 Great :)Edit your original post and put *SOLVED* in the title Link to comment https://forums.phpfreaks.com/topic/30414-populating-a-drop-down-field/#findComment-140022 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.