Jump to content

change choice to whatever is selected.


newb

Recommended Posts

[code]
<?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>   
?>
[/code]

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?
Link to comment
https://forums.phpfreaks.com/topic/23457-change-choice-to-whatever-is-selected/
Share on other sites

[code]
<?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>";
?>
[/code]
incase anyone wanted to know how it was done

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.