读书人

怎么通过列表中某一个属性来显示具有相

发布时间: 2013-06-25 23:45:42 作者: rapoo

如何通过列表中某一个属性来显示具有相同属性的内容
这是我的课题列表,我的课题列表中有一列是“状态”来显示“可选”或“不可选”的。目前列表显示的是所有可选和不可选的内容。我想添加一个功能,就是通过点击“可选”后,系统自动调用数据库中状态为“可选”的内容;点击“不可选”后,系统又能自动调用数据库中状态为“不可选”的内容。

<?php
//######################课题列表##########################
include "conn.php";
include "header.php";
?>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">

<link href="style.css" rel="stylesheet" type="text/css">
<title>课题列表</title>
<style type="text/css">
<!--
.STYLE1 {font-size: 14px}
-->
</style>
<table width="740" border="0" cellspacing="1" cellpadding="0" bgcolor="#333333" align="center">
<tr>
<td width="60" height="30" bgcolor="#CDE6C7"> <div align="center" class="text"> <p class="STYLE1">课题编号</p></div> </td>
<td width="300" height="30" bgcolor="#CDE6C7"> <div align="center" class="title STYLE1">课题名称</div> </td>
<td width="85" height="30" bgcolor="#CDE6C7"> <div align="center" class="STYLE1">指导教师</div></td>
<td width="60" height="30" bgcolor="#CDE6C7"> <div align="center" class="STYLE1">职称</div> </td>
<td width="60" height="30" bgcolor="#CDE6C7"> <div align="center" class="title STYLE1">可选人数</div> </td>
<td width="80" height="30" bgcolor="#CDE6C7" class="title"><div align="center" class="STYLE1">选题情况</div> </td>
<td width="60" height="30" bgcolor="#CDE6C7" class="title"><div align="center" class="STYLE1">状态</div> </td>
<td width="60" height="30" bgcolor="#CDE6C7" class="title"><div align="center" class="STYLE1">详细资料</div> </td>
</tr>
<?php
extract($_REQUEST);
$n=0;
$query=mysql_query("select count(*) as sm from jiaoshi");
mysql_query("set names 'GB2312'");
$row=mysql_fetch_array($query);
$count=$row['sm'];
if(empty($offset))
{$offset=0;}
echo $offset;
$query=mysql_query("select * from jiaoshi order by id asc limit $offset,$list_num") or die ("fail");
mysql_query("set names 'GB2312'");
while($row=mysql_fetch_array($query)){
if(($n%2)!='0'){
echo "<tr bgcolor=#CDE6C7>";}
else{
echo "<tr bgcolor=#FFFFFF>";
}
if($row['surplus']==0)
$ss="不可选";
else $ss="可选";
echo"
<td height='22' class='STYLE1'> <div align='center'>".$row['id']."</div></td>
<td height='22' class='STYLE1'> <div align='center'>".$row['subject']."</div></td>


<td height='22' class='STYLE1'> <div align='center'>".$row['teacher']."</div></td>
<td height='22' class='STYLE1'> <div align='center'>".$row['zhicheng']."</div></td>
<td height='22' class='STYLE1'> <div align='center'>".$row['number']."</div></td>
<td height='22' class='STYLE1'> <div align='center'>".$row['xuehao']."</div></td>
<td height='22' class='STYLE1'> <div align='center'>".$ss."</div></td>
<td height='22' class='STYLE1'> <div align='center'> <a href=xiangxiziliao.php?id=".$row['id'].">查看</a></div></td>
</tr> ";
$n++;
}
?></table>


[解决办法]
$surplus=''; //放在这个位置
extract($_REQUEST);

$query=mysql_query("select count(*) as sm from keti $where");
[解决办法]
不知道你是怎么学的
把下面的代码放在单独的文件里,运行一下
<?php
extract($_REQUEST);
?>
<form name='myform' action='' method='post' >
<select name='surplus' onchange="document.myform.submit()">
<option value=0 <?php echo isset($surplus) && $surplus ==0 ? 'selected' : ''; ?>>不可选</option>
<option value=1 <?php echo isset($surplus) && $surplus ==1 ? 'selected' : ''; ?>>可选</option>
</select>
</form>

读书人网 >PHP

热点推荐