<?php require_once('../conn.php');?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link href="css.css" rel="stylesheet" type="text/css" />
</head><body>
<div class="title">Reviews</div>
<form id="form1" name="form1" method="get" action="Reviews.php">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td valign="bottom">
      ProductID=
          <input name="ProductID" type="text" id="ProductID" style="border:#CCC groove 1px;" value="<?=$_GET['ProductID']?>" />
          <input type="submit" name="Submit" value="Search" />
    </td>
    <td width="250" class="btn">&nbsp;</td>
  </tr>
</table><table width="100%" border="0" cellspacing="1" cellpadding="5">
  <tr>
    <td width="3%" class="TabTitle">NO.</td>
    <td width="5%" class="TabTitle">ProductNO.</td>
    <td width="12%" class="TabTitle">Name &amp; Email </td>
    <td width="30%" class="TabTitle">Review</td>
    <td width="33%" class="TabTitle">Reply</td>
    <td width="5%" class="TabTitle">State</td>
    <td width="12%" class="TabTitle">Operation</td>
  </tr>
<?php
$ProductID = $_GET['ProductID'];
$list_num=12;
$sql="select count(*) from review";
if(!empty($ProductID)){
$sql = $sql.' where ProductID='.$ProductID;
}
$result=mysql_query($sql,$conn);
$rs=mysql_fetch_array($result);
$num=$rs[0];
$pagenumber=ceil($num/$list_num);
if(empty($_REQUEST['page']))$page=1;
else{
    $page=$_REQUEST['page'];
    if($page<1) $page=1;
    if($page>=$pagenumber) $page=$pagenumber;
}$sql="select * from review ";
if(!empty($ProductID)){
$sql = $sql.' where ProductID='.$ProductID;
}
$sql=$sql." order by UpdateTime desc limit ".(($page-1)*$list_num).",".$list_num; 
$result=mysql_query($sql,$conn);
$i=0;
while($rs=mysql_fetch_object($result))
{
$i=$i+1;?>
  <tr>
    <td align="center" class="TabTd"><?=$i?></td>
    <td align="center" class="TabTd"><a href="http://www.globalsourcesdirect.com/servlet/the-<?=$rs->ProductID?>/review/Detail" target="_blank"><?=$rs->ProductID?></a></td>
    <td class="TabTd"><?=$rs->Name?><br><a href="mailto:<?=$rs->Email?>" class="reviewSmall"><?=$rs->Email?></a><br /><span class="reviewSmall"><?=$rs->IP?></span></td>
    <td class="TabTd"><?=$rs->Content?><br /><div class="reviewSmall">( <?=$rs->UpdateTime?> )</div></td>
    <td class="TabTd"><?=$rs->Reply?><?php if($rs->Reply<>""){?><br /><div class="reviewSmall">( <?=$rs->ReplyName?> <?=$rs->ReplyTime?> )</div><?php }?></td>
    <td align="center" class="TabTd"><a href="Function.php?Act=ChangeReviewState&amp;ID=<?=$rs->ID?>&amp;State=<?=$rs->State?><?=$urlStr?>">
      <?php if($rs->State == "Active") echo "<span class=active>Active</span>"; else echo "Inactive";?>
    </a></td>
    <td class="TabTd"><a href="Function.php?Act=DelReview&amp;ID=<?php echo $rs->ID;?>">Delete</a>&nbsp; <a href="ReviewEdit.php?ID=<?php echo $rs->ID;?>">Edit</a>&nbsp; <a href="ReviewReply.php?ID=<?=$rs->ID?>">Reply</a></td>
  </tr>
<?php }?>
</table>
<div class="page">
<?php
if($page>1) echo "<a href='?page=".($page-1)."&ProductID=$ProductID'>Prev</a> ";
else echo "Prev ";
for ($i=1;$i<=($pagenumber);$i++){
    if($page<>$i) echo "<a href='?page=".$i."&ProductID=$ProductID'>".$i."</a> ";
    else echo $i." ";
}
if($page<$pagenumber) echo " <a href='?page=".($page+1)."&ProductID=$ProductID'>Next</a>";
else echo " Next";
?>
</div>
</form></body>
</html>

解决方案 »

  1.   

    谢谢penglewen 的回答
    这种方法我理解
    但是如果我还要加State='Active'的筛选,或者其他筛选,那是不是一直都要把$State这些也加在后面呢
    有没有更好的办法?
      

  2.   

    好像是ProductID 没有得到,你在分页那儿鼠标放在那儿看看,你的ProductID 是否已经赋值成功。或者是点击之后看看地址栏里是否有你需要的值。
      

  3.   


    理解正确.
    如果不想用这种方式的话,可以将State放到session里.
    但要保证适时的清除这个信息.
      

  4.   


    写到Session里,果然是个好办法,但是适时的清除这个Session,这个不太好把握,我现在就试一下,谢谢!我还想问一下,那些CMS系统的后台,比如DEDE,动易,在列表页有很多这样的功能,比如“已通过审核”“未通过审核”,还有显示某个栏目下的所有文章
    他们都是用什么方法的呢?
      

  5.   


    是的,没有什么好办法要用State='Active'或limit输出如果你只想一次取出后分页是静态的,即不动态更新,放在session中也是好办法,session无容量限制,只是要注意删除机制