我有一个可以编辑的下拉菜单;
// Connect to Local Host
@ $db=mysqli_connect('localhost', 'root');
if (!$db) { do_Warning(-1); exit; }
// Connect to Database
@ mysqli_select_db($db,'coshh');
echo '<tr><td>Harmful effects:</td>
<td><select name="Harmful_effects"><option></option>';
/* Create SQL to extract effects options */
$sql = "SELECT * FROM `lookup_harmful_to_reproductive_system` ORDER BY `id`";
/* Perform SQL to get effects options */
$result = mysqli_query($db, $sql);
/* Build dropdown list for each effects option found in result */
while ($row=mysqli_fetch_array($result,MYSQLI_BOTH))
{
echo '<OPTION value="'.$row['Harmful_effects'].'"';
if ($Harmful_effects == $row['Harmful_effects'])
{
echo ' selected';
}
echo '>'.$row['Harmful_effects'].'</OPTION>';
}
echo '</select></select></td>';
但是,我被要求将其更改为一个多选项下拉菜单,我已经这样做了,它将多个选项插入到我的 MySQL 数据库中。我遇到的一个大问题是,当您编辑这个多重下拉菜单时,它不会突出显示以前从数据库中选择/输入的数据。我已经开始了,但我真的很难绕过它;
echo '<tr><td>Harmful effects:</td>
<td><select name="Harmful_effects[]" multiple="multiple" STYLE="width: 500px" size="0"><option></option>';
/* Create SQL to extract effects options */
$sql = "SELECT * FROM `lookup_harmful_to_reproductive_system` ORDER BY `id`";
/* Perform SQL to get effects options */
$result = mysqli_query($db, $sql);
/* Build dropdown list for each effects option found in result */
while ($row=mysqli_fetch_array($result,MYSQLI_BOTH))
{
echo '<OPTION value="'.$row['Harmful_effects'].'"';
if ($Harmful_effects == $row['Harmful_effects'])
{
echo ' selected';
} echo '>'.$row['Harmful_effects'].'</OPTION>';
} echo '</select></select></td>';
任何建议/帮助将不胜感激!