haha.php
<?
include_once 'sqldb.php';
function getcid($user,$pass,$database,$dns)
{
$adress = $_SERVER['HTTP_HOST'];
$add = explode('.',$adress);
$dbactive = new sqldb($adress,$user,$pass);
//$dbactive->select_db($database);
if($add[0]== "www")
{
if($add[1]!=$dns)//判断是否是本服务器的域名;如果不是就检查数据库,找出cid
{
//查找数据库
$result = $dbactive->query("28door","select cid from MAIN_CITY where city =".$add[1]);
$dbactive->free();
if($row = mysql_fetch_array($result))
{
$cid = $row[0];
}
else
{
$cid = 999;
}
}
else
{
$cid=999;
}
}
else
{
//取$add[0]对数据库进行判断
$result = $dbactive->query("28door","select cid from MAIN_CITY where city =".$add[0]);
$dbactive->free();
//
//判断$add[0]代表的城市是否存在
if($row = mysql_fetch_array($result))
{
$cid = $row[0];
}
else
{
$cid = 999;
}

}
$dbactive->close();
return $cid;
}
?>*************************************************************************************
test.php
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title></head><body>
<?
include_once 'haha.php'
?>
<select  name="selCat">
<option value="">请选择类别</option>
<?
    $i=0;
   while($i <10)
   {
?>
<option value="<?=$i?>"><? echo "哈哈哈哈"?></option>
<?
$i=$i+1;
}
?>
</select>
<?
$cid=getcid("root","","28door","daopian");
echo $cid;
?>
</body>
</html>