学院首页>网络编程>PHP>支持oicq头像的留言簿(一)

支持oicq头像的留言簿(一)

作者: 来源:不详 添加时间:2006-5-25 20:42:22
  特点:
支持oicq头像,自动分页,显示留言人ip,email合法性验证,方便安全的留言管理,
没有复杂函数,初学者也很容易看懂。
程序示例:http://medguider.51.net/notebook/
完整程序下载(包括图片)http://medguider.51.net/download/notebook.zip
程序清单:
config.php 配置文件 mysql.txt 数据库文件 index.php 显示留言主程序 addnote.php 添加留言 delnote.php 删除留言
mysql.txt
create table notebook (name char(6),email varchar(35),time char(30),face char(2),ip varchar(16),title varchar(255),nnote text);
//留言簿 name 姓名 email time 时间 face 头像 ip title 标题 nnote 内容
config.php
<?php
//这里改为自己的数据库用户名与密码
$db = mysql_connect("localhost", "root");
mysql_select_db("test",$db);
//这里改为自己的管理用户名和密码
$username="demo";
$password="demo";
?>
index.php
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<TITLE>留言簿</TITLE>
<style type="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>
<BODY BGCOLOR="#FFFFFF">
<?php
include ("config.php");
$result = mysql_query("SELECT * FROM notebook ",$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 * from notebook ORDER BY time DESC limit $low,$x",$db);//按照帖子的时间降序查询
?>
<table width="98%" border="0" cellspacing="0" cellpadding="0" height="61">
  <tr>  
 <td height="62" width="34%"><a href="http://www.medguider.com"><img src="/edu/files/pic/2006-5/25/0652520421950354.gif"" width="243" height="60" alt="医学导航网" border="0"></a></td>
 <td height="62" width="66%">  
<div align="center"><img src="/edu/files/pic/2006-5/25/0652520421982427.gif"" width="410" height="60"><img src="/edu/files/pic/2006-5/25/065252042208164.gif"" width="60" height="60"></div>
 </td>
  </tr>
</table>
<table width="95%" border="1" cellspacing="0" cellpadding="0" height="253" bordercolordark="#FFFFFF" bordercolorlight="#003399" align="center">
  <tr>  
 <td height="250">  
<div align="center"></div>
<table width="95%" border="0" cellspacing="0" cellpadding="0" height="32" bgcolor="#3366FF">
  <tr>  
 <td width="26%" height="23"><a href="../index.php" 留言簿</td>
 <td width="48%" height="23">  
<?php
 echo "帖子总数: &nbsp;",$max," &nbsp;&nbsp;第";
 for ($n=1;$n<=$p;$n++){
 echo "<a href=index.php?page=$n>$n</a>&nbsp;";
 }
 echo "页";
 ?>
 </td>
 <td width="15%" height="23"><a href="addnote.php"><img src="/edu/files/pic/2006-5/25/0652520422085075.gif"" width="91" height="21" border="0"></a></td>
 <td width="11%" height="23"><a href="delnote.php"><span
  </tr>
</table>  
<?php
for ($i=0;$i<=($x-1);$i++) {
$name=mysql_result($result,$i,'name');
$email=mysql_result($result,$i,'email');
$face=mysql_result($result,$i,'face');
$face='image/face/icon'.$face; //用户头像
$time=mysql_result($result,$i,'time');
$ip=mysql_result($result,$i,'ip');
$title=mysql_result($result,$i,'title');
$nnote=mysql_result($result,$i,'nnote');
echo "<table width='100%' border='0' cellspacing='0' cellpadding='0' height=107' bordercolor='#FFFFFF'> <tr bgcolor='#eeeeee'>";  
echo "<td width='10%' height='33' bgcolor='#eeeeee' src="/edu/files/pic/2006-5/25/065252042218044.gif" width='32' height='32'></td>";
echo  "<td width='16%' height='33' bgcolor='#eeeeee'
echo  "<td width='41%' height='33' bgcolor='#eeeeee'
echo  "<td width='12%' height='33' bgcolor='#eeeeee' href='mailto:$email'><img src="/edu/files/pic/2006-5/25/0652520422183765.gif" width='16' height='16' border=0></a></td>";
echo  "<td width='21%' height='33' src="/edu/files/pic/2006-5/25/0652520422248738.gif" width='13' height='15'> &nbsp;$ip</td>  </tr> <tr>";  
echo  "<td colspan='5' height='33'>标题:$title</td> </tr>";
echo  "<tr bgcolor='#ffffff'><td colspan='5' height='37'>留言内容:$nnote</td></tr></table>";
}
mysql_close($db);
?>  
 </td>
</tr>
</table>
</BODY>
</HTML>  
站内搜索