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
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.