这是我的课题列表,我的课题列表中有一列是“状态”来显示“可选”或“不可选”的。目前列表显示的是所有可选和不可选的内容。我想添加一个功能,就是通过点击“可选”后,系统自动调用数据库中状态为“可选”的内容;点击“不可选”后,系统又能自动调用数据库中状态为“不可选”的内容。
<?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>

解决方案 »

  1.   

    功能类似你的查看,点击之后弄一个链接,然后把id传过去,update该条记录。
      

  2.   

    加个select框,监听onchange 事件,然后form提交实现过滤记录。
      

  3.   

    <form name='myform' action='' method='post'>
    <select name='surplus' onchange="document.myform.submit()">
    <option value=0>不可选</option>
    <option value=1>可选</option>
    </select>
    </form> $where=isset($_POST['surplus']) ? " where surplus=".$_POST['surplus'] : '';
     $query=mysql_query("select * from jiaoshi $where order by id asc limit $offset,$list_num") or die ("fail");
      

  4.   

    <form name='myform' action='' method='post'>
    <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' onclick='func(".$row['surplus'].")'>".$ss."</div></td>
        <td   height='22' class='STYLE1'> <div align='center'> <a href=xiangxiziliao.php?id=".$row['id'].">查看</a></div></td>
      </tr> ";
       $n++;
       }
       ?></table>
    <input type='hidden' name='surplus' id='surplus' />
    </form>
    <script>
    function func(v){
           document.getElementById('surplus').value=v;
           document.myform.submit();
    }
    </script>
      

  5.   

     $where=($_POST['surplus']=="") ? '' : " where surplus=".$_POST['surplus'] ;
     $query=mysql_query("select * from jiaoshi $where order by id asc limit $offset,$list_num") or die ("fail"); 
      

  6.   

    我按你给我的第一种方法写的,但是系统提示错误Undefined index: surplus 在第46行。<?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"> 
     <form name='myform' action='' method='post' >
      <select name='surplus' onchange="document.myform.submit()">
       <option value=0>不可选</option>
       <option value=1>可选</option>
      </select>
     </form>
      <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;*/
       $where=($_POST['surplus']=="") ? '' : " where surplus=".$_POST['surplus'] ;
       $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>
      

  7.   

    46 行的 $where=($_POST['surplus']=="") ? '' : " where surplus=".$_POST['surplus'] ;
    应写作 $where=(isset($surplus)) ? '' : " where surplus='$surplus'";原因是 37 的 extract($_REQUEST); 已经将外来的变量导入到变量表中了
    所以不再需要从 $_POST 中读取,何况也不一定是 post 方式传入的
      

  8.   

    extract这个函数生成的变量应该还是局部变量吧
      

  9.   

    我修改后系统提示又变成Undefined variable: surplus 在46行。还有就是,您给看看我这种方法能实现点“可选”实现列表显示所有可选的内容不?
      

  10.   

    不好意思,写反了!
    应该这样:
    $where = (! isset($surplus)) ? '' : " where surplus='$surplus'";
      

  11.   

    嗯,这下没有错误了,嘿嘿。但是那个可选不可选功能仍然没有实现,我应该再怎么修改下呢?<?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"> 
     <form name='myform' action='' method='post' >
      <select name='surplus' onchange="document.myform.submit()">
       <option value=0>不可选</option>
       <option value=1>可选</option>
      </select>
     </form>
      <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;
       $where = (! isset($surplus)) ? '' : " where surplus='$surplus'";
       $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>
      
      

  12.   

    第18-24行<form name='myform' action='' method='post' >
      <select name='surplus' onchange="document.myform.submit()">
       <option value=0>不可选</option>
       <option value=1>可选</option>
      </select>
     </form>
      

  13.   

    $query=mysql_query("select * from jiaoshi $where order by id asc limit $offset,$list_num") or die ("fail");
      

  14.   

    那我应该把这两句放在哪呢?$where = (! isset($surplus)) ? '' : " where surplus='$surplus'";
    $query=mysql_query("select * from jiaoshi $where order by id asc limit $offset,$list_num") or die ("fail"); 
      

  15.   

    <option value=1>可选</option>
    改为:
    <option value=1 <?php if($surplus==1) echo 'selected';?> >可选</option>但是内容应该有变化了才对啊
      

  16.   

    print "<td width='170'><a href=\"?offset=$preoffset&surplus=$surplus\">上一页</a></td>";}if(($pages!=0)&&(($newoffset/$list_num)!=$pages))
        {
         print("<td width='170'><a  href=\"?offset=$newoffset&surplus=$surplus\">下一页</a></td>");
        }$where = (! isset($surplus)) ? '' : " where surplus='$surplus'";
    这句改为:
    $where = (isset($surplus) && strlen($surplus)>0) ? " where surplus='$surplus'" : '';
      

  17.   

    这是我改完后的,点可选后每一页都是可选了,就是有一点小问题,它提示第90行有一个未定义的变量 Undefined variable: surplus这是怎么回事呢?<?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"> 
     <form name='myform' action='' method='post' >
      <select name='surplus' onchange="document.myform.submit()">
       <option value=0>不可选</option>
       <option value=1>可选</option>
      </select>
     </form>
      <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 keti");
      mysql_query("set names 'GB2312'");
      $row=mysql_fetch_array($query);
      $count=$row['sm'];
        if(empty($offset))
                  {$offset=0;}
    /*echo  $offset;*/
       $where = (isset($surplus) && strlen($surplus)>0) ? " where surplus='$surplus'" : ''; 
       $query=mysql_query("select * from keti $where 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>
      
     <?php
         $pages=ceil($count/$list_num);
           echo "<table width=740 border=0 cellspacing=0 cellpadding=0 align=center class='text'>
              <tbody> 
              <tr> 
         <td width='290'><font color='#ff0000'>目前共有".$count."条记录</font> </td>  
     <td width='245'>共".$pages."页</td>";
    if($offset){
       $preoffset=$offset-$list_num;
    print "<td width='170'><a href=\"?offset=0\">首页</a></td><td width='170'><a href=\"?offset=$preoffset&surplus=$surplus\">上一页</a></td>";}
    else {
      echo "<td width='170'>首页</td><td width='170'>上一页</td>";}
       $nextoffset=$offset+$list_num;
    if(($pages!=0)&&(($nextoffset/$list_num)!=$pages))
    {
     print("<td width='170'><a  href=\"?offset=$nextoffset&surplus=$surplus\">下一页</a></td>");}
     else{ echo "<td width='170'>下一页</td>";}
        
    $pageno=($offset/$list_num)+1;
    echo "<td width='112' class=text>第<input class=text type='text' size='3' value=".$pageno." readonly>页</td>
          <td width='4'>&nbsp;</td></tr>
    </table>"; 
    ?>     
    <p>
    </p>
    <?php include "foot.php";?>
      

  18.   

    $surplus 只在选择了下拉框后才会有
    你需要在 37 行前为 $surplus 赋初值
    或在 90 行做条件判断都在做毕设了,怎么连基本常识都不知道?
      

  19.   

    唉,惭愧惭愧,身为这个专业的人也没有为这个专业发光发热,尽拖后腿了……
    那我在第37行给surplus赋个什么值呢$surplus=?;
    话说版主你今天终于理我了,那我就厚着脸皮再问你个问题,当我点“可选”后,列表下边的还是显示的所有“可选”和“不可选”的总记录和总页数,怎么能让它显示成我点完“可选”后的记录和页数?
      

  20.   

    $surplus = '';  就可以。你的总记录数和总页数是通过
    $query=mysql_query("select count(*) as sm from jiaoshi");
    这句算出来的 ,你需要将where条件也加入进去
      

  21.   

    给surplus赋个什么值呢
    赋什么值都不合适!
    只要一赋值,就变成条件查询了
    也就是一开始的 可选和不可选 共存的情况就没有了
    这是你的数据组织有问题而造成的计算总记录和总页数应放在 46 行以后进行
      

  22.   

    你们太伟大了。我还以为只说一下思路,居然HMTL都出来了。
      

  23.   

    那这样写对吗?$query=mysql_query("select count(*) as sm from jiaoshi where surplus=$surplus");
      

  24.   

    将下面几行放在$where 的下面就可以了
    $query=mysql_query("select count(*) as sm from keti");
      mysql_query("set names 'GB2312'");
      $row=mysql_fetch_array($query);
      $count=$row['sm'];
      

  25.   

    如果加上这句的话“可选”功能就失效了,我就先把它注释掉了。$surplus='';
    这是我最新修改的,把那几句换了位置后总记录数和总页数没什么变化。<?php
    //######################课题列表##########################
      include "conn.php";
      include "header.php";
      /*error_reporting(E_ALL ^ E_NOTICE);*/
    ?> 
    <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"> 
     <form name='myform' action='' method='post' >
      <select name='surplus' onchange="document.myform.submit()">
       <option value=0>不可选</option>
       <option value=1>可选</option>
      </select>
     </form>
      <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;
      /*$surplus='';*/
         if(empty($offset))
                 {$offset=0;}
        /*echo  $offset;*/
      $where = (isset($surplus) && strlen($surplus)>0) ? " where surplus='$surplus'" : ''; 
      $query=mysql_query("select count(*) as sm from keti");
      mysql_query("set names 'GB2312'");
      $row=mysql_fetch_array($query);
      $count=$row['sm'];
      
      $query=mysql_query("select count(*) as sm from keti");
      mysql_query("set names 'GB2312'");
      $row=mysql_fetch_array($query);
      $count=$row['sm'];
      
       $query=mysql_query("select * from keti $where 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>
      
     <?php
        $pages=ceil($count/$list_num);
           echo "<table width=740 border=0 cellspacing=0 cellpadding=0 align=center class='text'>
              <tbody> 
              <tr> 
         <td width='290'><font color='#ff0000'>目前共有".$count."条记录</font> </td>  
     <td width='245'>共".$pages."页</td>";
    if($offset){
       $preoffset=$offset-$list_num;
    print "<td width='170'><a href=\"?offset=0\">首页</a></td><td width='170'><a href=\"?offset=$preoffset&surplus=$surplus\">上一页</a></td>";}
    else {
      echo "<td width='170'>首页</td><td width='170'>上一页</td>";}
       $nextoffset=$offset+$list_num;
    if(($pages!=0)&&(($nextoffset/$list_num)!=$pages))
    {
     print("<td width='170'><a  href=\"?offset=$nextoffset&surplus=$surplus\">下一页</a></td><td width='170'>");}
     else{ echo "<td width='170'>下一页</td>";}
        
    $pageno=ceil(($offset/$list_num)+1);
    echo "<td width='112' class=text>第<input class=text type='text' size='3' value=".$pageno." readonly>页</td>
          <td width='4'>&nbsp;</td></tr>
    </table>"; 
    ?>     
    <p>
    </p>
    <?php include "foot.php";?>
      

  26.   

    $surplus=''; //放在这个位置
    extract($_REQUEST);$query=mysql_query("select count(*) as sm from keti $where");
      

  27.   

    这是我最新的代码,仍然无法实现的功能就是,它无法计算点击“可选”后的总条数和总页数。<?php
    //######################课题列表##########################
      include "conn.php";
      include "header.php";
      error_reporting(E_ALL ^ E_NOTICE);
    ?> 
    <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"> 
      <form name='myform' action='' method='post'>
      <select name='surplus' onchange="document.myform.submit()">
       <option value=0>不可选</option>
       <option value=1>可选</option>
      </select>
     </form>
      <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
      $surplus='';
      extract($_REQUEST);
      $n=0;
         if(empty($offset))
                 {$offset=0;}
        /*echo  $offset;*/
      $where = (isset($surplus) && strlen($surplus)>0) ? " where surplus='$surplus'" : ''; 
      $query=mysql_query("select count(*) as sm from keti $where");
      mysql_query("set names 'GB2312'");
      $row=mysql_fetch_array($query);
      $count=$row['sm'];
      
      $query=mysql_query("select count(*) as sm from keti");
      mysql_query("set names 'GB2312'");
      $row=mysql_fetch_array($query);
      $count=$row['sm'];
      
       $query=mysql_query("select * from keti $where 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>
      
     <?php
        $pages=ceil($count/$list_num);
           echo "<table width=740 border=0 cellspacing=0 cellpadding=0 align=center class='text'>
              <tbody> 
              <tr> 
         <td width='290'><font color='#ff0000'>目前共有".$count."条记录</font> </td>  
     <td width='245'>共".$pages."页</td>";
    if($offset){
       $preoffset=$offset-$list_num;
    print "<td width='170'><a href=\"?offset=0\">首页</a></td><td width='170'><a href=\"?offset=$preoffset&surplus=$surplus\">上一页</a></td>";}
    else {
      echo "<td width='170'>首页</td><td width='170'>上一页</td>";}
       $nextoffset=$offset+$list_num;
    if(($pages!=0)&&(($nextoffset/$list_num)!=$pages))
    {
     print("<td width='170'><a  href=\"?offset=$nextoffset&surplus=$surplus\">下一页</a></td>");}
     else{ echo "<td width='170'>下一页</td>";}
        
    $pageno=ceil(($offset/$list_num)+1);
    echo "<td width='112' class=text>第<input class=text type='text' size='3' value=".$pageno." readonly>页</td>
          <td width='4'>&nbsp;</td></tr>
    </table>"; 
    ?>     
    <p>
    </p>
    <?php include "foot.php";?>
      

  28.   

    44 到 56 行改成
      mysql_query("set names 'GB2312'");
      $where = (isset($surplus) && strlen($surplus)>0) ? " where surplus='$surplus'" : ''; 
      $query=mysql_query("select count(*) as sm from keti $where");
      $row=mysql_fetch_array($query);
      $count=$row['sm']; //总记录数
       
      $query=mysql_query("select * from keti $where order by id asc limit $offset,$list_num") or die ("fail");
      

  29.   

    还有一个小问题,我一点“可选”,内容可以正常显示,但是“可选”和“不可选”的form表单里就弹回到不可选了?like this
    点“可选”后,又弹回不可选。
      

  30.   

     <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>
      

  31.   

    不知道你是怎么学的
    把下面的代码放在单独的文件里,运行一下
    <?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>