Jump to content

Select Option Help


dennismonsewicz

Recommended Posts

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

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

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.