weird select drop down box error. content spilling out on page
Weird issue the country names are no longer being listed in the select dropdown box they're just spilling out all over the page. can anyone spot the coding error that is causing it?
echo "<select name=recordcountry style='width: 136px;'>";
//echo "<option value=$country selected=selected>-- Select --</option>";
echo "<option ". ($data['recordcountry'] == "" ? 'selected=selected>-- Select --</option>' : 'value="' .$data['recordcountry']. '" selected=selected');
$group1 = '<optgroup label=Common>';
$group2 = '<optgroup label=Alphabetically>';
$group = mysql_query("SELECT coun开发者_开发知识库try, grouping, p_order FROM mast_country
WHERE grouping IN ('1','2') ORDER BY p_order");
while($row = mysql_fetch_array($group))
{
if ($row['grouping'] == '1')
{
$group1 .= '<option value="'.$row['country'].'">'.
$row['country'].'</option>';
}
else
{
$group2 .= '<option value="'.$row['country'].'">'.
$row['country'].'</option>';
}
$group1 .= '</otpgroup>';
$group2 .= '</otpgroup>';
echo $group1;
echo $group2;
echo "</select>";
}
It's </optgroup>
, not </otpgroup>
.
echo "<option ". ($data['recordcountry'] == "" ? 'selected=selected>-- Select --</option>' : 'value="' .$data['recordcountry']. '" selected=selected');
makes no sense, too. It is highly confusing and you are not adding </option>
.
Here's a better version:
echo '<option value="'.$data['recordcountry'].'"'.($data['recordcountry'] ? '' : ' selected="selected"').'>'.($data['recordcountry'] ? $data['recordcountry'] : '--Select--').'</option>';
Or even better, split it into two lines and use an IF statement:
if($data['recordcountry'])
echo '<option value="'.$data['recordcountry'].'">'.$data['recordcountry'].'</option>';
else
echo '<option value="" selected="selected">--Select--</option>';
I think the problem is in this line.
echo "<option ". ($data['recordcountry'] == "" ? 'selected=selected>-- Select --</option>' : 'value="' .$data['recordcountry']. '" selected=selected');
No end tag is added when $data['recordcountry'] == ""
. Should be something like this i think.
echo "<option ". ($data['recordcountry'] == "" ? 'selected=selected>-- Select --</option>' : 'value="' .$data['recordcountry']. '" selected='selected'>" . $data['recordcountry'] . "</option>");
Edit: And what ThiefMaster said
精彩评论