k9204,女司机撞交警,张信哲经典歌曲下载
初学php,花了几晚上写了个留言板,请高手指正
p.s.我的空间不支持php,不能提供演示了t_t
数据库结构:(库名: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>银子留言板 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">偶要发表</a></li>
<?php
//session_start();//dofy同学指出本句前不能有任何输出内容,就此改正
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">银子留言板 version 1.0</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\">银子留言板 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(首页)
<?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,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 href="http://wpa.qq.com/msgrd?v=1&uin=<?= $row[3] ?>&site=http://www.loai.cn&menu=yes"><img src="img/qq.gif" alt="<?= $row[3]?>" /></a><? } ?><? if($row[4]){ ?> <a href="mailto:<?= $row[4] ?>"><img src="img/email.gif" alt="<?= $row[4]?>" /></a> <? }?><? if($_session["key"]==1){ ?> ip:<?= $row[6] ?> <a href="update.php?wuleying&id=<?= $row[0]?>">更改</a> <a href="delete.php?wuleying&id=<?= $row[0]?>">删除</a><?}?></a></p>
<p class="blue">留言内容:</p>
<div id="show_info"><?= nl2br(htmlspecialchars($row[5])) ?></div>
</div>
<?php
}
}
else
{
echo "<div id=\"show\">无数据......</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> 页 | 当前第 <span><?= $page ?></span> 页 | 共 <span><?=$numrows ?></span> 条留言</p>
</div>
<?php
mysql_close();
?>
<?php
require_once("footer.php");
?>
1
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!!
点击进行留言回复
相关文章:
-
-
-
-
Yii框架应用组件用法实例分析
本文实例讲述了yii框架应用组件用法。分享给大家供大家参考,具体如下:应用组件 应用主体是, 它部署一组提供各种不同功能的 应用组件 来处理请求。 例如,url...
[阅读全文]
-
-
-
-
-
Yii 框架入口脚本示例分析
本文实例讲述了yii 框架入口脚本。分享给大家供大家参考,具体如下:入口脚本入口脚本是应用启动流程中的第一环, 一个应用(不管是网页应用还是控制台应用)只有一个...
[阅读全文]
-
PHP强制转化的形式整理
php强制转化有几种形式php强制转化有3种形式:1、在要转换的变量之前加上用括号括起来的目标类型;2、使用转强函数,如“intval()”,“strval()...
[阅读全文]
-
php7 新增功能实例总结
本文实例总结了php7 新增功能。分享给大家供大家参考,具体如下:一、核心 增加了group use语法声明。rfc: https://wiki.php.ne...
[阅读全文]
网友评论