p.s.我的空間不支持php,不能提供演示了T_T
數(shù)據(jù)庫結(jié)構(gòu):(庫名: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(連接數(shù)據(jù)庫文件)
<?php
mysql_connect("localhost","root","");//連接數(shù)據(jù)庫
mysql_select_db("lyb");//選擇數(shù)據(jù)庫
?>
2 header.php(公用頭部文件)
復(fù)制代碼 代碼如下:
<!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>銀子留言板 Version 1.0</title>
</head>
<link href="css.css" rel="stylesheet" type="text/css" />
<body>
<?php session_start(); ?>
<div id="head">
<div id="head_l">
<ul>
<li><a href="index.php">偶要看留言</a></li>
<li><a href="post.php">偶要發(fā)表</a></li>
<?php
//session_start();//DOFY同學(xué)指出本句前不能有任何輸出內(nèi)容,就此改正
if($_SESSION["key"]==1){//如果獲取的SESSION為1則顯示管理項(xiàng)
?>
<li><a href="adminexit.php">退出管理</a></li>
<?
}
else
{
?>
<li><a href="admin.php">偶要管理</a></li>
<?}?>
</ul>
</div>
<div id="head_r">銀子留言板 Version 1.0</div>
</div>
3 footer.php(公用底部文件)
復(fù)制代碼 代碼如下:
<?php
$counterFile="conter.xml";
function displayCounter($counterFile){
$fp = fopen($counterFile,"rw");
$num = fgets($fp,5);
$num += 1;
print "<div id=/"footer/">銀子留言板 Version 1.0 您是第 "."$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(首頁)
復(fù)制代碼 代碼如下:
<?php
require_once("conn.php");
require_once("header.php");
session_start();
//分頁代碼開始
$pagesize = 10;//設(shè)置每頁顯示條數(shù)
$rs = mysql_query("select count(*) from lo");//取得記錄總數(shù),計(jì)算總頁數(shù)用
$myrow = mysql_fetch_array($rs);
$numrows = $myrow[0];//計(jì)算總記錄
$pages = intval($numrows/$pagesize);
if($numrows%$pagesize)$pages++;//設(shè)置頁數(shù)
if(isset($_GET['page']))
{
$page = intval($_GET['page']);
}
else
{
$page = 1;//設(shè)為第一頁
}
$offset = $pagesize*($page-1);//計(jì)算記錄偏移量
//分頁代碼結(jié)束
$sql = "select id,username,sex,qq,email,info,ip,DATE_FORMAT(submit_time, '%Y年%m月%d日 %T' ) from lo order by id desc limit $offset,$pagesize";//用到了DATE-FORMAT格式化日期格式
$result = mysql_query($sql);
$num = mysql_num_rows($result);
if($num>0){
while($row = mysql_fetch_array($result))
{
//echo print_r($row);
if($row[2]=="男")//這個使性別改成你想要的名稱^_^
{
$sex = "帥鍋";
}
else
{
$sex = "美女";
}
?>
<div id="show">
<p class="num">第 [<?= $row[0] ?>] 條留言<p>
<p class="unline">留言人:<span class="blue"><?= $row[1]?></span> 性別:<?= $sex ?> 留言時間:<?= $row[7] ?> <? if($row[3]) {?> <a update.php?wuleying&id=<?= $row[0]?>">更改</a> <a href="delete.php?wuleying&id=<?= $row[0]?>">刪除</a><?}?></a></p>
<p class="blue">留言內(nèi)容:</p>
<div id="show_info"><?= nl2br(htmlspecialchars($row[5])) ?></div>
</div>
<?php
}
}
else
{
echo "<div id=/"show/">無數(shù)據(jù)......</div>";
}
?>
<div id="show_page">
<p>
<?php
$first=1;
$prev=$page-1;
$next=$page+1;
$last=$pages;
if($page==1&&$pages>1)
{
echo "首頁 | ";
echo " | ";
echo "<a href=/"index.php?page=".$next."/"></a> | ";
echo "<a href=/"index.php?page=".$last."/">尾頁</a> | ";
}
elseif($page>=1&&$page!=$pages&&$num>0)
{
echo "<a href=/"index.php?page=".$first."/">首頁</a> | ";
echo "<a href=/"index.php?page=".$prev."/"></a> | ";
echo "<a href=/"index.php?page=".$next."/"></a> | ";
echo "<a href=/"index.php?page=".$last."/">尾頁</a> | ";
}
elseif($page==$pages&&$page!=1)
{
echo "<a href=/"index.php?page=".$first."/">首頁</a> | ";
echo "<a href=/"index.php?page=".$prev."/"></a> | ";
echo " | ";
echo "尾頁 | ";
}
elseif($page==$pages)
{
echo "首頁 | ";
echo " | ";
echo " | ";
echo "尾頁 | ";
}
else
{
echo "首頁 | ";
echo " | ";
echo " | ";
echo "尾頁 | ";
}
?>
共 <span><?= $pages ?></span> 頁 | 當(dāng)前第 <span><?= $page ?></span> 頁 | 共 <span><?=$numrows ?></span> 條留言</p>
</div>
<?php
mysql_close();
?>
<?php
require_once("footer.php");
?>
php技術(shù):一個簡單的PHP&amp;MYSQL留言板源碼第1/2頁,轉(zhuǎn)載需保留來源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。