如何获取此代码以显示已选择的选项?
这基本上是一个编辑页面,它从数据库中提取信息并填充相关字段
我在页面上有一个下拉菜单、多个选择框和单选按钮以及一些元素。信息在元素中显示得很好,但我不知道如何让 s 和单选按钮显示选中,如果它们与数据库中的信息匹配。
代码:
<select name="client">
<option value="empty">Change Client...</option>
<?php
$result2 = mysql_query("SELECT name FROM clients") or die("Database query failed: " . mysql_error());
while($row = mysql_fetch_assoc($result2)) {
$clientlist = $row['name'];
$clientname = htmlspecialchars($row['name']);
if ($_POST['client'] == $clientlist)
{
echo '<option value="' . $clientlist . '" selected="selected" >' . $clientname . '</option>' . '\n';
}
else{
echo '<option value="' . $clientlist . '" >' . $clientname . '</option>' . '\n';
}
}
?>
</select>
</p>
<p class="subheadsmall">Core Classification</p>
<?php
switch ($niche) {
case "brand":
echo '<input type="radio" name="niche" value="Brand" checked="checked" />Brand';
echo '<input type="radio" name="niche" value="Marketing" />Marketing';
echo '<input type="radio" name="niche" value="Communication" />Communication';
break;
case "marketing":
echo '<input type="radio" name="niche" value="Brand" />Brand';
echo '<input type="radio" name="niche" value="Marketing" checked="checked" />Marketing';
echo '<input type="radio" name="niche" value="Communication" />Communication';
break;
case "communication":
echo '<input type="radio" name="niche" value="Brand" />Brand';
echo '<input type="radio" name="niche" value="Marketing" />Marketing';
echo '<input type="radio" name="niche" value="Communication" checked="checked" />Communication';
break;
default;
echo '<input type="radio" name="niche" value="Brand" />Brand';
echo '<input type="radio" name="niche" value="Marketing" />Marketing';
echo '<input type="radio" name="niche" value="Communication" />Communication';
break;
}
?>
<p class="subheadsmall">Strategies</p>
<p class="sidebargrey">
<?php
$result = mysql_query("SELECT strategies FROM studies WHERE id = '$id';
if (!$result) {
die("Database query failed: " . mysql_error());
}
while($row = mysql_fetch_array($result)) {
$strategyname = $row['strategies'];
echo $strategyname.'<br />';
}
?>
<p class="subheadsmall">Add a strategy... (hold down command key to select more than one)</p>
<select name="strategies[]" multiple="multiple">
<?php
$result = mysql_query("SELECT * FROM strategies");
if (!$result) {
die("Database query failed: " . mysql_error());
}
while($row = mysql_fetch_array($result)) {
$strategylist = $row['name'];
$strategyname = htmlspecialchars($row['name']);
$pagelink = str_replace(" ","_",$strategylist);
echo '<option value="<a href="strategies.php?strategy=' . $pagelink . '">'.$strategyname.'</a>" >' . $strategyname . '</option>' . '\n';
}
?>
</p>