想要默认选中下拉列表的某一个分类
<?php
include_once("./connect.php");
$sql="select * from ts_news_cates";//要执行的语句
$re=mysql_query($sql);//执行命令
/*
定义一个空数组;
如果执行的语句行数大于0.(说明执行成功,有记录条数)
输出一个结果(
要用循环做出来,不知道循环多少次,用while循环。
把上面执行的sql语句的结$re放在关联数组$info中;
当这个$info 数组不为假时,把$info的结果放在数组$arr中。
)
getCates($arr);是在引用的页面定义的一个函数;
把getCates函数调用一下,结果放在$infos变量中。
*/
$arr=array();
if(mysql_num_rows($re)>0){
while(($info=mysql_fetch_assoc($re))!=false){
$arr[]=$info;
}
}
$infos=getCates($arr);
$cid=$_GET['cid'];
echo $cid;
?>
<!DOCTYPE HTML >
<html>
<head>
<title> 添加新闻子分类 </title>
<meta charset="utf-8">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<link rel="stylesheet" type="text/css" href="skin/css/base.css"/>
<link rel="stylesheet" type="text/css" href="skin/css/main.css"/>
</head>
<body leftmargin="8" topmargin='8'>
<table width="98%"
align="center"
border="0"
cellpadding="3"
cellspacing="1"
bgcolor="#CBD8AC"
style="margin-bottom:8px;margin-top:8px;"
>
<tr>
<td background="skin/images/frame/wbg.gif" bgcolor="#EEF4EA" class='title' colspan="2">
<span>
<img src='skin/images/frame/arr3.gif' style='margin-right:10px;'>添加新闻子分类
</span>
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td>
<form action="./act_add_newscates.php" method="post">
<table style="margin-bottom:8px;margin-top:8px;margin-left:20px;" >
<tr>
<td width="100px;">上级分类:</td>
<td>
<select name="fid">
<option value=0>顶级分类</option>
<!--遍历$infos数组-->
<?php foreach($infos as $key=>$vo){?>
<option value=<?="1"?> selected>
<?=str_repeat(" ",$vo['level']-1).$vo['cname']?>
</option>
<?php }?>
</select>
</td>
</tr>
<tr>
<td>分类名称:</td>
<td>
<input type="text" name="cname" value=""/>
</td>
</tr>
<tr>
<td>首页是否显示</td>
<td>
<input type="radio" name="show" value="1" checked="true">显示
<input type="radio" name="show" value="0">不显示
</td>
</tr>
<tr>
<td colspan="2" align="center" height="40px">
<input type="submit" name="sub" value="添加" class="coolbt2">
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>