dennismonsewicz Posted April 6, 2010 Share Posted April 6, 2010 I am trying to ck my database and if the result runs and finds a particular answer that matches in the select option then it is supposed to select it, but I can't figure it out.. <?php foreach($ck_results as $row) { if($row->turned_on == 1) { $s = 'SELECTED=SELECTED'; } elseif($row->turned_on == 0) { $s = 'SELECTED=SELECTED'; } else { $s = ''; } } ?> <select name="maintenance"> <option value="1" <?=$s;?>>YES</option> <option value="0" <?=$s;?>>NO</option> </select> Thanks for any and all help! Link to comment https://forums.phpfreaks.com/topic/197804-select-option-help/ Share on other sites More sharing options...
dennismonsewicz Posted April 6, 2010 Author Share Posted April 6, 2010 nevermind fixed my problem... <?php function selectOption($ck_opt) { $arr = array('1' => 'YES', '0' => 'NO'); $s = ''; echo '<select name="maintenance">'; foreach($arr as $key=>$val) { if($key == $ck_opt) { $s = 'selected="selected"'; } echo '<option value="' . $key , '" ' . $s . '>' . $val . '</option>'; } echo '</select>'; } foreach($ck_results as $row) { echo selectOption($row->turned_on); } ?> Link to comment https://forums.phpfreaks.com/topic/197804-select-option-help/#findComment-1038033 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.