zl程序教程

您现在的位置是:首页 >  其它

当前栏目

杏林同学录(七)

同学录 杏林
2023-06-13 09:13:44 时间
留言簿部分:
   班级成员留言簿:显示留言:class/notebook/index.php
<?
session_start();//开始session
if(!session_is_registered("userregister")||($userregister==""))//检查是否注册,如userregister未注册或session为空值,重新注册.
{
echo"<ahref="../index.php">请重新注册<BR>";
exit;
}
?>
<HTML>
<HEAD>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312">
<TITLE>留言簿</TITLE>
<styletype="text/css">
<!--
.blue9{  font-size:9pt;color:#0099FF;text-decoration:none}
.black9{  font-size:9pt;text-decoration:none}
.purple10{  font-size:10pt;color:#9900FF;text-decoration:none}
.white12{  font-size:12pt;color:#FFFFFF;text-decoration:none}
a:visited{  color:#FFFFFF}
a:link{  color:#FFFFFF}
-->
</style>
</HEAD>
<BODYBGCOLOR="#FFFFFF">
<?php
include("../config.php");
$result=mysql_query("SELECT*FROMnotebook",$db);
$row=mysql_num_rows($result);//查看查询结果有多少行
$max=$row;//帖子总数
//设每页显示10篇,可自行设定,$p总页数,$page第几页,$low从第几行开始读,$x读取几行
if(!$page){$page=1;}//$page默认值为1
$p=ceil($max/10);//页数为$max/10的最大整数
$low=10*($page-1);
if($page==$p&&($max%10)<>0){$x=($max%10);}else{$x=10;}//如果是最后一页,且不是10的整倍数,读取$max除以10的余数,否则取10
if($max==0){$x=0;}//如果没有帖子,$x取0
$result=mysql_query("select*fromnotebookORDERBYtimeDESClimit$low,$x",$db);//按照帖子的时间降序查询
?>
<tablewidth="98%"border="0"cellspacing="0"cellpadding="0"height="61">
  <tr>  
    <tdheight="62"width="34%"><imgsrc="../image/classlogo.gif"width="224"height="60"  border="0"></td>
    <tdheight="62"width="66%">  
      <divalign="center"><imgsrc="../image/note.gif"width="410"height="60"><imgsrc="../image/y1.gif"width="60"height="60"></div>
    </td>
  </tr>
</table>
<tablewidth="95%"border="1"cellspacing="0"cellpadding="0"height="253"bordercolordark="#FFFFFF"bordercolorlight="#003399"align="center">
  <tr>  
    <tdheight="250">  
      <divalign="center"></div>
      <tablewidth="95%"border="0"cellspacing="0"cellpadding="0"height="32"bgcolor="#3366FF">
        <tr>  
          <tdwidth="26%"class="white12"height="23"><ahref="../guest.php"class="white12">首页</a>  
            >留言簿</td>
          <tdwidth="48%"class="white12"height="23">  
            <?php
          echo"帖子总数: ",$max,"  第";
          for($n=1;$n<=$p;$n++){
          echo"<ahref=index.php?page=$n>$n</a> ";
          }
          echo"页";
          ?>
          </td>
          <tdwidth="15%"height="23"><ahref="addnote.php"><imgsrc="../image/newthread.gif"width="91"height="21"border="0"></a></td>
          <tdwidth="11%"height="23"><ahref="delnote.php"><spanclass="white12">留言管理</span></a></td>
        </tr>
      </table>  
<?php
   for($i=0;$i<=($x-1);$i++){
   $user=mysql_result($result,$i,"user");
   $time=mysql_result($result,$i,"time");
   $ip=mysql_result($result,$i,"ip");
   $title=mysql_result($result,$i,"title");
   $nnote=mysql_result($result,$i,"nnote");
   $yresult=mysql_query("SELECT*FROMuserwhereuser="$user"",$db);//读取成员数据库
   $name=mysql_result($yresult,0,"name");
   $signature=mysql_result($yresult,0,"signature");//读取个人签名
   $email=mysql_result($yresult,0,"email");
   $face=mysql_result($yresult,0,"face");
   $face="../image/face/icon".$face;

echo"<tablewidth="100%"border="0"cellspacing="0"cellpadding="0"height=107"bordercolor="#FFFFFF"><trbgcolor="#eeeeee">";  
echo"<tdwidth="10%"height="33"bgcolor="#eeeeee"class="blue9"> <imgsrc="$face.gif"width="32"height="32"></td>";
echo        "<tdwidth="16%"height="33"bgcolor="#eeeeee"class="blue9">留言人:$name</td>";
echo        "<tdwidth="41%"height="33"bgcolor="#eeeeee"class="blue9">发表于:$time</td>";
echo        "<tdwidth="12%"height="33"bgcolor="#eeeeee"class="blue9"><ahref="mailto:$email"><imgsrc="../image/email.gif"width="16"height="16"border=0></a></td>";
echo        "<tdwidth="21%"height="33"class="blue9"><imgsrc="../image/ip.gif"width="13"height="15"> $ip</td>  </tr><tr>";  
echo        "<tdcolspan="5"class="purple10"height="33">标题:$title</td></tr>";
echo        "<trbgcolor="#ffffff"><tdcolspan="5"class="black9"height="37">留言内容:$nnote<BR>----------------------<BR>$signature</td></tr></table>";
}
mysql_close($db);
?>     
    </td>
</tr>
</table>
</BODY>
</HTML>
添加留言:class/notebook/addnote.php
<?
session_start();//开始session
if(!session_is_registered("userregister")||($userregister==""))//检查是否注册,如userregister未注册或session为空值,重新注册.
{
echo"<ahref="../index.php">请重新注册<BR>";
exit;
}
?>
<HTML>
<HEAD>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312">
<TITLE>添加留言</TITLE>
<styletype="text/css">
<!--
.white12{  font-size:12pt;color:#FFFFFF;text-decoration:none}
-->
</style>
</HEAD>
<BODYBGCOLOR="#FFFFFF">
<tablewidth="98%"border="0"cellspacing="0"cellpadding="0"height="61">
  <tr>  
    <tdheight="62"width="34%"><imgsrc="../image/classlogo.gif"width="224"height="60"border="0"></td>
    <tdheight="62"width="66%">  
      <divalign="center"><imgsrc="../image/note.gif"width="410"height="60"><imgsrc="../image/y1.gif"width="60"height="60"></div>
    </td>
  </tr>
</table>
<?php
include("../config.php");
if($submit){
$time=date("Y年m月d日H:i:sA");
$ip=$REMOTE_ADDR;//留言人ip地址
$title=strip_tags($top);
$nnote=nl2br(strip_tags($content));//先去掉html标记,再将换行符转成<br>。
if(!$title||!$nnote){           //检查是否填写完整
      echo"对不起,您必须填所有内容!<BR>"."<ahref="javascript:history.back()">返回</a>";
      exit;}
   //写入数据库
$sql="INSERTINTOnotebook(user,time,ip,title,nnote)VALUES("$userregister","$time","$ip","$title","$nnote")";
$result=mysql_query($sql,$db);
mysql_close($db);
echo"留言成功!";
}
?>
<tablewidth="99%"border="1"cellspacing="0"cellpadding="0"align="center"bordercolor="#3366FF">
  <trbgcolor="#3366FF">  
    <tdwidth="81%"class="white12"height="26"><ahref="../../main.php"class="white12">首页</a>  
      ><ahref="index.php"class="white12">留言簿</a>>添加留言</td>
    <tdwidth="19%"class="white12"height="26"><ahref="index.php"class="white12">查看留言</a>  
    </td>
  </tr>
  <tr>  
    <tdcolspan="2">
      <formname="form1"method="post"action="addnote.php">
        <tablewidth="99%"border="0"cellspacing="0"cellpadding="0">
          <tr>  
            <td>  
              <divalign="center">标题<br>
                <inputtype="text"name="top"size="50">
                <br>
                内容<br>
                <textareaname="content"cols="50"rows="6"></textarea>
                <br>
                <inputtype="submit"name="submit"value="确定">
                <inputtype="reset"name="cancel"value="重写">
              </div>
            </td>
          </tr>
        </table>
              </form>
    </td>
  </tr>
</table>
<p><ahref="main.php?user=<?echo$user?>"class="white12"><br>
  </a></p>
</BODY>
</HTML>