$r=mysql_query("SELECT city.id as city_id,city.city_name,locality.id,locality.area_name ".
"FROM city, locality ".
"WHERE city.id = locality .city_id order by city_id");
$previous = '';
while($rss=mysql_fetch_object($r)) { ?>
<?php if (empty($previous) || $previous != $rss->city_id) { ?>
<legend><?=$rss->city_name?></legend>
<?php } ?>
<?php $previous = $rss->city_id; ?>
<input type="checkbox" name="sub_type[]" id="sub_type" value="<?=$rss->id?>" />
<span><?=$rss->area_name?></span><br/>
<?php
}
?>
这是我的城市名称和地区名称记录,在复选框中列出现在我想在选择框中显示相同的东西,城市名称为红色,然后其子区域名称,其小例子在http://www.99acres.com/作为城市在这个网站上显示
答案 0 :(得分:0)
无需为您编写代码,您应该能够调整此代码以满足您的需求。
<select name="SELECTNAME">
<?php while($rss=mysql_fetch_object($r)) {
echo '<option value="' . $value . '" ';
if () { // Put your if statement code here for when you want the option to be coloured red.
echo 'YOUR RED CLASS';
}
echo '>' . $name . '</option>';
}
?>
</select>
答案 1 :(得分:0)
这就是你想要的:
$r=mysql_query("SELECT city.id as city_id,city.city_name,locality.id,locality.area_name ".
"FROM city, locality ".
"WHERE city.id = locality .city_id order by city_id");
$previous = '';
?>
<select name="foo">
<?php while($rss=mysql_fetch_object($r)) { ?>
<?php if (empty($previous) || $previous != $rss->city_id) { ?>
<option name="city[]" style="color:red" value="<?=$rss->city_name?>"><?=$rss->city_name?></option>
<?php } ?>
<?php $previous = $rss->city_id; ?>
<option name="sub_type[]" id="sub_type" value="<?=$rss->id?>"><?=$rss->area_name?></option>
<?php } ?>
</select>