用php+mysql实现带回复功能的留言板(二)

相关文章
用php+mysql实现带回复功能的留言板(一)
用php+mysql实现带回复功能的留言板(三)
用php+mysql实现带回复功能的留言板(四)
用php+mysql实现带回复功能的留言板(五)
主文件guestbook.php源程序如下:

<?session_start();?>
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>你的名字</title>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="12" bgcolor="#99CC55" colspan="2"> <font size="2">
      <? require ("../opendata.php"?>
      </font> <font size="2">
      <? require ("../online.php")?>
      你的位置:<a href="../default.php">首页</a>-&gt;&gt; 留言板</font></td>
  </tr>
  <tr>
    <td height="65" bgcolor="#CCCC99" width="47%">
      <div align="left"><font size="2">谁可以发表新贴:凡注册了的会员<br>
        谁可以回复贴子:凡注册了的会员<br>
        谁可以删除贴子:凡本站管理员</font></div>
    </td>
    <td height="65" bgcolor="#CCCC99" width="53%"><font size="2">凡发表的贴子必须符合法律,文明与道德,<br>否则管理员在不通知的情况下将其删除。</font></td>
  </tr>
</table>

  
<font size="2">
<?
delete_left_user
();
if(!
update_last_time($session_userid))
?>
<?
if($page!=""&$action=="show")
{
 
$rs=mysql_fetch_array(mysql_query("select count(*) from guestbook where rid is null or rid=0",$cn));
 
$max_page=$rs[0];

$pagesize=10;

if(
$page>=$max_page)
$page=$max_page-$pagesize;
if(
$page<=0)
$page=0;
$result=mysql_query("select * from guestbook where rid is null or rid=0 order by id desc  limit ".$page.",".($currentpage+$pagesize),$cn);
?>
</font>
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="33">
   <form action=guestbook.php?action=search method="post"> <tr bgcolor="#99CC00">
      
      <td width="39%" height="35"><font size="2"> 主题数(不包括回复贴): 
        <?=$max_page;?>
        </font></td>
      
    <td width="61%" height="35"> 
     <font size="2"> 查找内容
        <input type="text" name="content" size="20">
        查找对像
        <select name="select">
          <option><font size="2">标题</font></option>
          <option><font size="2">作者</font></option>
          <option><font size="2">内容</font></option>
        </select>
        <input type="submit" name="search" value="go">
        </font>  </td>
    </tr> </form>
  </table>


<p align="right"><font size="2">
  <?if($page>=1){?>
  <a href=guestbook.php?page=0&action=show>第一页</a>
  <?}?>
  <?if($page>=1){?>
  &nbsp&nbsp<a href=guestbook.php?page=<?=$page-$pagesize;?>&action=show>上一页</a>
  <?}?>
  <?if($page<$max_page-$pagesize){?>
  &nbsp&nbsp<a href=guestbook.php?page=<?=$page+$pagesize;?>&action=show>下一页</a>
  <?}?>
  <?if($page<$max_page-$pagesize){?>
  &nbsp&nbsp<a href=guestbook.php?page=<?=$max_page-$pagesize;?>&action=show>最后页</a>
  <?}?>
  </font></p>
<table border="0" width="100%" height="58" cellspacing="0" cellpadding="0">
  <tr bgcolor="#00CCFF">
    <td width="75" height="25">
      <div align="left"><font size="2">编号</font></div>
    </td>
    <td width="71" height="25">
      <div align="left"><font size="2">大名</font></div>
    </td>
    <td width="288" height="25">
      <div align="left"><font size="2">标题</font></div>
    </td>
    <td width="48" height="25">
      <div align="left"><font size="2">人气</font></div>
    </td>
    <td width="45" height="25">
      <div align="left"><font size="2">回复</font></div>
    </td>
    <td width="252" height="25">
      <div align="left"><font size="2">留言时间</font></div>
    </td>
  </tr>
  <tr></tr>
  <?

while ($rs=mysql_fetch_array($result))
{

?>
  <tr bgcolor="#99CC00">
    <td width="75" height="25"> <font size="2">
      <?=$rs["id"];?>
      <?if($session_power>=1)
      {
      
?>
      <a href="sign.php?action=delete&database=guestbook&id=<?=$rs["id"];?>">删除</a> </font> </td>
    <?}?>
    <td width="71" height="25"> <font size="2">
      <?=$rs["userid"];?>
      </font>

    </td>
    <td width="288" height="25" bgcolor="#99CC00"> <font size="2"><a href=guestbook.php?show_id=<?=$rs["id"];?>&action=show_reply>
      <?=$rs["title"];?>
      </a>  </font> </td>
    <td width="48" height="25"> <font size="2">
      <?=$rs["click"];?>
      </font>

    </td>
    <td width="45" height="25"> <font size="2">
      <?=$rs["rnum"];?>
      </font>

    </td>
    <td width="252" height="25"> <font size="2">
      <?=$rs["ttime"];?>
      </font> </td>
  </tr>
  <tr></tr>
  <?}?>
</table>
<div align="right">
  <p><font size="2">
    <?if($page>=1){?>
    <a href=guestbook.php?page=0&action=show>第一页</a>
    <?}?>
    <?if($page>=1){?>
    &nbsp&nbsp<a href=guestbook.php?page=<?=$page-$pagesize;?>&action=show>上一页</a>
    <?}?>
    <?if($page<$max_page-$pagesize){?>
    &nbsp&nbsp<a href=guestbook.php?page=<?=$page+$pagesize;?>&action=show>下一页</a>
    <?}?>
    <?if($page<$max_page-$pagesize){?>
    &nbsp&nbsp<a href=guestbook.php?page=<?=$max_page-$pagesize;?>&action=show>最后页</a>
    <?}?>
    </font></p>

</div>
<form method="POST" action="sign.php?action=sign">
  <table width="100%" border="0" cellspacing="0" cellpadding="0" height="155">
    <tr>
      <td height="20" width="20%"><font size="2">发表新贴</font></td>
      <td height="20" width="68%">&nbsp;</td>
    </tr>
    <tr>
      <td width="20%"><font size="2">标题:</font></td>
      <td width="68%"> <font size="2">
        <input type="text" name="title" size="20">
        </font></td>
    </tr>
    <tr>
      <td width="20%"><font size="2">内容:</font></td>
      <td width="68%" rowspan="2"> <font size="2">
        <textarea rows="8" name="say" cols="40"></textarea>
        </font></td>
    </tr>
    <tr>
      <td width="20%">&nbsp;</td>
    </tr>
  </table>
  <p align="left"> <font size="2">
    <input type="submit" value="提交" name="sign">
    <input type="reset" value="重写" >
    </font>
</form>
<font size="2">
<?}?>
</font>
  <?
if($show_id!=""&$action=="show_reply")
{
?>
<div align="right"> <font size="2">
  <br>
  <a href=guestbook.php?page=0&action=show>主题列表</a></font></div>
<p align="center"><font size="2"><br>
  <?
  
if(!$no_update_click)
   
mysql_query("update guestbook set click=click+1 where id=".$show_id);
 
$rs=mysql_fetch_array(mysql_query("select * from guestbook where id=".$show_id,$cn));
  
$re_title=$rs["title"];
 
$reply_id=$rs["id"]; ?>
  </font></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="81">
  <tr>
    <td width="38%" bgcolor="#3399FF"><font size="2">标题:
      <?=$rs["title"];?>
      <br>
      大名:
      <?=$rs["userid"];?>
      <br>
      留言时间:
      <?=$rs["ttime"];?>
      </font></td>
    <td width="62%" bgcolor="#CCCC33"><font size="2">
      <?=$rs["say"];?>
      </font></td>
  </tr>
</table>
<p align="left"><font size="2">
  
  </font><font size="2" color="#FF0000">以下是该贴的回复</font><font size="2"> </font></p>
  <?
 
if($rs["id"]!=0)
 {
        
$result=mysql_query("select * from guestbook where guestbook.rid=".$rs["id"],$cn);

        while(
$rs=mysql_fetch_array($result))
        {
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="81">
  <tr>
    <td width="38%" bgcolor="#CCFFCC"><font size="2">
        <?if($session_power>=1)
        {
?>
        <a href="sign.php?action=delete&database=rguestbook&rid=<?=$rs["rid"];?>&id=<?=$rs["id"];?>">删除</a>
        <?}?><br>标题:
      <?=$rs["title"];?>
      <br>
      大名:
      <?=$rs["userid"];?>
      <br>
      留言时间:
      <?=$rs["ttime"];?>
      </font></td>
    <td width="62%" bgcolor="#99CCFF"><font size="2">
      <?=$rs["say"];?>
      </font></td>
  </tr>
</table>
<p align="left"> <font size="2">
  <?
         
}
 }
 
?>
<?
if($no_reply=="")
{
?>
  </font></p>
<form method="POST" action="sign.php?action=reply&reply_id=<?=$reply_id;?>">
  <table width="100%" border="0" cellspacing="0" cellpadding="0" height="128">
    <tr>
      <td height="30">
        <div align="left"><font size="2">回复该贴 </font></div>
      </td>
      <td height="30">&nbsp;</td>
    </tr>
    <tr>
      <td><font size="2">标题:</font></td>
      <td> <font size="2">
        <input type="text" name="title" size="20" value="<?="RE:".$re_title;?>">
        </font></td>
    </tr>
    <tr>
      <td><font size="2">回复内容:</font></td>
      <td rowspan="2"> <font size="2">
        <textarea rows="8" name="say" cols="34"></textarea>
        </font></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
    </tr>
  </table>
  <p align="left">
   <font size="2">
    <input type="submit" value="提交" >
    <input type="reset" value="重写" >
    </font></p>
</form>

<?
 
}
 }
  
?>
<p>
  <?

 
if($action=="search")
 {
 
?>
  <?
  
echo "查找:".$content."<br>方式:".$select."查找"
 
?>
  <br>
  <font size="2">
  <?
  
//原贴查找
  
if($select=="标题")
  {
 
$rs=mysql_fetch_array(mysql_query("select count(*) from guestbook where title like('%".$content."%')",$cn));
 
$max_page=$rs[0];
 
$pagesize=10;
 if(
$page>=$max_page)
$page=$max_page-$pagesize;
if(
$page<=0)
$page=0;
$sql="select * from guestbook  where title like('%".$content."%') limit ".$page.",".($currentpage+$pagesize);
$result=mysql_query($sql,$cn);
}

if(
$select=="作者")
{
 
$rs=mysql_fetch_array(mysql_query("select count(*) from guestbook where userid like('%".$content."%')",$cn));
 
$max_page=$rs[0];
 
$pagesize=10;
 if(
$page>=$max_page)
$page=$max_page-$pagesize;
if(
$page<=0)
$page=0;
$sql="select * from guestbook  where userid like('%".$content."%') limit ".$page.",".($currentpage+$pagesize);
$result=mysql_query($sql,$cn);
}
if(
$select=="内容")
{
 
$rs=mysql_fetch_array(mysql_query("select count(*) from guestbook where say like('%".$content."%')",$cn));
 
$max_page=$rs[0];
 
$pagesize=10;
 if(
$page>=$max_page)
$page=$max_page-$pagesize;
if(
$page<=0)
$page=0;
$sql="select * from guestbook  where say like('%".$content."%') limit ".$page.",".($currentpage+$pagesize);
$result=mysql_query($sql,$cn);
}
//以上是原贴查找

if($max_page==0)
echo 
"<p align=center><font size=4 color=red>对不起,没能找到你想要的记录</font></p><br>";
else
{
echo 
"<font size=4 color=red>共找到".$max_page."记录</font>"
?>
  </font>
<p align="right"><font size="2">
  <?if($page>=1){?>
  <a href=guestbook.php?page=0&action=search&content=<?=$content;?>&select=<?=$select?>>第一页</a>
  <?}?>
  <?if($page>=1){?>
  &nbsp&nbsp<a href=guestbook.php?page=<?=$page-$pagesize;?>&action=search&content=<?=$content;?>&select=<?=$select?>>上一页</a>
  <?}?>
  <?if($page<$max_page-$pagesize){?>
  &nbsp&nbsp<a href=guestbook.php?page=<?=$page+$pagesize;?>&action=search&content=<?=$content;?>&select=<?=$select?>>下一页</a>
  <?}?>
  <?if($page<$max_page-$pagesize){?>
  &nbsp&nbsp<a href=guestbook.php?page=<?=$max_page-$pagesize;?>&action=search&content=<?=$content;?>&select=<?=$select?>>最后页</a>
  <?}?>
  </font></p>
<table border="0" width="100%" height="58" cellspacing="0" cellpadding="0">
  <tr bgcolor="#00CCFF">
    <td width="75" height="25">
      <div align="left"><font size="2">编号</font></div>
    </td>
    <td width="71" height="25">
      <div align="left"><font size="2">大名</font></div>
    </td>
    <td width="288" height="25">
      <div align="left"><font size="2">标题</font></div>
    </td>
    <td width="252" height="25">
      <div align="left"><font size="2">留言时间</font></div>
    </td>
  </tr>
  <?
 
}
while (
$rs=mysql_fetch_array($result))
{

?>
  <tr bgcolor="#99CC00">
    <td width="75" height="25"> <font size="2">
      <?=$rs["id"];?>
      <?if($session_power>=1)
      {
      
?>
      <a href="sign.php?action=delete&database=guestbook&id=<?=$rs["id"];?>">删除</a>
      </font> </td>
    <?}?>
    <td width="71" height="25"> <font size="2">
      <?=$rs["userid"];?>
      </font> </td>
    <td width="288" height="25" bgcolor="#99CC00"> <font size="2"><a href=guestbook.php?show_id=<?=$rs["id"];?>&action=show_reply&no_reply=1 target=_blank>
      <?=$rs["title"];?>
      </a>  </font> </td>
    <td width="252" height="25"> <font size="2">
      <?=$rs["ttime"];?>
      </font> </td>
  </tr>
  <?}?>
</table>
<div align="right">
  <p><font size="2">
    <?if($page>=1){?>
    <a href=guestbook.php?page=0&action=search&content=<?=$content;?>&select=<?=$select?>>第一页</a>
    <?}?>
    <?if($page>=1){?>
    &nbsp&nbsp<a href=guestbook.php?page=<?=$page-$pagesize;?>&action=search&content=<?=$content;?>&select=<?=$select?>>上一页</a>
    <?}?>
    <?if($page<$max_page-$pagesize){?>
    &nbsp&nbsp<a href=guestbook.php?page=<?=$page+$pagesize;?>&action=search&content=<?=$content;?>&select=<?=$select?>>下一页</a>
    <?}?>
    <?if($page<$max_page-$pagesize){?>
    &nbsp&nbsp<a href=guestbook.php?page=<?=$max_page-$pagesize;?>&action=search&content=<?=$content;?>&select=<?=$select?>>最后页</a>
    <?}?>
    </font></p>
</div>
<p>&nbsp;
<p> <a href="guestbook.php?page=0&action=show">返回 </a> </p>

<?}?>
</body>
</html>