Jump to content

Archived

This topic is now archived and is closed to further replies.

newb

change choice to whatever is selected.

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?

Share this post


Link to post
Share on other sites
Inside the loop: [code]$selected = $row['is_selected'] ? " selected='selected'" : null;
echo "\n<option value='$row['id']'{$selected}>$row['name']</option>\n";[/code]

Share this post


Link to post
Share on other sites
didnt work., i dont have a $row'is_selected' field in my table.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

×

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.