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! Quote Link to comment 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); } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.