Jump to content


Photo

change choice to whatever is selected.


  • Please log in to reply
5 replies to this topic

#1 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 09 October 2006 - 06:30 PM

<?php
  $query = $config->query("SELECT * FROM table_modules");
            echo "<select name='conf_default_mod'>";
			while ($row = mysql_fetch_array($query)) {
			echo "\n<option value='$row[id]'>$row[name]</option>\n";
			}
            echo "
          </select>     
?>

how do i change the code so that it echo's whatever option is selected in the database. like selected="selected" . any one know how?

#2 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 09 October 2006 - 06:36 PM

Inside the loop:
$selected = $row['is_selected'] ? " selected='selected'" : null;
echo "\n<option value='$row['id']'{$selected}>$row['name']</option>\n";


#3 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 09 October 2006 - 06:45 PM

didnt work., i dont have a $row'is_selected' field in my table.

#4 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 09 October 2006 - 06:46 PM

No, but use what corresponds to your database structure.

#5 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 09 October 2006 - 06:50 PM

ah i got it to work :D

#6 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 09 October 2006 - 06:52 PM

<?php
		  $query = $config->query("SELECT * FROM table_modules");
            echo "<select name='conf_default_mod'>";
			while ($row = mysql_fetch_array($query)) {
			$option = "\n<option value='$row[id]'>$row[name]</option>\n";
			
				$query2 = $config->query("SELECT * FROM table_settings WHERE id='11'");
				$row2 = mysql_fetch_array($query2);
				$def_mod = $row2['value'];
				
					if(eregi("$def_mod",$option)) {
					$option = str_replace($option,"\n<option value='$row[id]' selected='selected'>$row[name]</option>\n",$option);		
					} else { $option = "\n<option value='$row[id]'>$row[name]</option>\n"; }
			
			echo $option;
			}
            echo "
          </select>";
?>
incase anyone wanted to know how it was done




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users