日期:2012-10-18  浏览次数:20412 次

数据库结构:(库名:lyb)
表一: admin
字段: id(int11)   name(varchvr)   password(varchvr)

表二: lo
字段: id(int11)   username(varchvr)  sex(varchvr)  qq(varchvr)  email(varchvr)  info(text)  ip(varchvr)  submit_time(datetime)

1 conn.php(连接数据库文件)

<?php
mysql_connect("localhost","root","");//连接数据库
mysql_select_db("lyb");//选择数据库
?>

2 header.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=gb2312" />
<title>PHP和MYSQL联合打造简单留言本程序</title>
</head>
<link href="css.css" rel="stylesheet" type="text/css" />
<body>
<div id="head">
    <div id="head_l">
        <ul>
            <li><a href="index.php">偶要看留言</a></li>
            <li><a href="post.php">偶要发表</a></li>
            <?php
            session_start();
            if($_SESSION["key"]==1){//如果获取的SESSION为1则显示管理项
            ?>
            <li><a href="adminexit.php">退出管理</a></li>
            <?
            }
            else
            {
            ?>
            <li><a href="admin.php">偶要管理</a></li>
            <?}?>
        </ul>
    </div>
    <div id="head_r">PHP和MYSQL联合打造简单留言本程序</div>
</div>

3 footer.php(公用底部文件)

<?php
$counterFile="conter.xml";
function displayCounter($counterFile){
$fp  =  fopen($counterFile,"rw");
$num =  fgets($fp,5);
$num += 1;
print "<div id=\"footer\">简单留言板   您是第 "."$num"." 位无聊的银</div>";
exec("rm -rf $counterFile");
exec("echo $num > $counterFile");
}
if(!file_exists($counterFile)){
exec("echo 0 > $counterFile");
}
displayCounter($counterFile);
?>
</body>
</html>

4 index.php(首页)

<?php
require_once("conn.php");
require_once("header.php");
session_start();
//分页代码开始
$pagesize = 10;//设置每页显示条数
$rs = mysql_query("select count(*) from lo");//取得记录总数,计算总页数用
$myrow = mysql_fetch_array($rs);
$numrows = $myrow[0];//计算总记录
$pages = intval($numrows/$pagesize);
if($numrows%$pagesize)$pages++;//设置页数
if(isset($_GET['page']))
    {
        $page = intval($_GET['page']);
    }
    else
    {
        $page = 1;//设为第一页
    }
$offset = $pagesize*($page-1);//计算记录偏移量
//分页代码结束
$sql = "select id,username,sex,qq,emai