我想给留言板加一下分页 每页显示5条数据 求大神指导 原代码如下
<?phpheader("Content-Type:text/html;charset=utf-8");date_default_timezone_set('Asia/S...
<?php
header("Content-Type: text/html;charset=utf-8");
date_default_timezone_set('Asia/Shanghai');
date_default_timezone_set('Asia/Shanghai');
define('DB_HOST', 'localhost');
define('DB_ROOT', 'root');
define('DB_MIMA', 'root');
define('DB_NAME', 'luntan');
$conn=mysql_connect('localhost','root','root') or die ("数据库连接失败,错误代码:".mysql_error());
mysql_select_db('luntan',$conn) or die('指定的数据库名称不存在,错误代码:'.mysql_error());
@$action = $_REQUEST["action"];
if ($action == "add" || $action == null)
{
?>
<form action='?action=addok' method='post'>
发表留言:</br>
<textarea name='content'></textarea></br>
<input type="submit" value='提交留言'>
<input type="reset" value='清空内容'>
</form>
<?php
}
if ($action == "addok")
{
$name=@$_COOKIE[user];
$time=time();
$content = $_REQUEST["content"];
if ($name=='') {
echo "<script>alert('请先登录');location.href='denglu.php'</script>";
# code...
}
if(empty($content)){
echo "<script>alert('留言不能为空');location.href='bbs.php?action=add'</script>";
}
else{
$sql1="INSERT INTO bbs(`name`,`cre_time`,`content`) values ('$name','$time','$content')";
mysql_query($sql1);
echo "<script>alert('留言成功');location.href='bbs.php?action=list'</script>";
}
}
if ($action == "list")
{
$sql2="SELECT * FROM bbs ORDER BY id asc";
$query2=mysql_query($sql2);
while ($row=mysql_fetch_array($query2)) {
echo "<pre>";
//print_r($row);
$nme='留言人:'.$row['name'];
$dat='留言时间:'.date('Y-m-d H:i:s',$row['cre_time']);
$con='留言内容:'.$row['content'];
echo $nme.'<br>'.$dat.'<br>'.$con.'<br>'.'<hr>';
}
}
?>
<input type="button" value="退出登录" onclick="document.location.href='denglu.php';setcookie('uesr','$_GET[user]', time()-3600)"> 展开
header("Content-Type: text/html;charset=utf-8");
date_default_timezone_set('Asia/Shanghai');
date_default_timezone_set('Asia/Shanghai');
define('DB_HOST', 'localhost');
define('DB_ROOT', 'root');
define('DB_MIMA', 'root');
define('DB_NAME', 'luntan');
$conn=mysql_connect('localhost','root','root') or die ("数据库连接失败,错误代码:".mysql_error());
mysql_select_db('luntan',$conn) or die('指定的数据库名称不存在,错误代码:'.mysql_error());
@$action = $_REQUEST["action"];
if ($action == "add" || $action == null)
{
?>
<form action='?action=addok' method='post'>
发表留言:</br>
<textarea name='content'></textarea></br>
<input type="submit" value='提交留言'>
<input type="reset" value='清空内容'>
</form>
<?php
}
if ($action == "addok")
{
$name=@$_COOKIE[user];
$time=time();
$content = $_REQUEST["content"];
if ($name=='') {
echo "<script>alert('请先登录');location.href='denglu.php'</script>";
# code...
}
if(empty($content)){
echo "<script>alert('留言不能为空');location.href='bbs.php?action=add'</script>";
}
else{
$sql1="INSERT INTO bbs(`name`,`cre_time`,`content`) values ('$name','$time','$content')";
mysql_query($sql1);
echo "<script>alert('留言成功');location.href='bbs.php?action=list'</script>";
}
}
if ($action == "list")
{
$sql2="SELECT * FROM bbs ORDER BY id asc";
$query2=mysql_query($sql2);
while ($row=mysql_fetch_array($query2)) {
echo "<pre>";
//print_r($row);
$nme='留言人:'.$row['name'];
$dat='留言时间:'.date('Y-m-d H:i:s',$row['cre_time']);
$con='留言内容:'.$row['content'];
echo $nme.'<br>'.$dat.'<br>'.$con.'<br>'.'<hr>';
}
}
?>
<input type="button" value="退出登录" onclick="document.location.href='denglu.php';setcookie('uesr','$_GET[user]', time()-3600)"> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询