<!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=utf-8" />
<title>分页</title>
</head><body>
<table border="0">
<tr>
<td width="202" height="12">公告标题</td>
<td width="202">公告内容</td>
</tr>
<?php
$link=mysql_connect("localhost","root","");
mysql_select_db("by",$link);
mysql_query("set names gb2312");
if($page=""){
$page=1;}
if(is_numeric($page)){
$page_size=4;
$result=mysql_query("select count(*) as total from a order by id desc");
$messmge_count=mysql_result($result,0,"total");
$page_count=ceil($messmge_count/$page_size);
$offset=($page-1)*$page_size;
$sql=mysql_query("select * from a order by id desc limit $offset,$page_size");
$row=mysql_fetch_object($sql);
if(!$row){
echo "<font color='red'>暂无公告信息</font>";
}
do{
?>
<tr>
<td><?php echo $row->name; ?></td>
<td><?php echo $row->mima; ?></td>
</tr>
<?php
}while ($row=mysql_fetch_object($sql));
}
?>
</table>
<table width="667" height="30" border="0">
<tr>
<td width="37%" align="left"> 页次:<?php echo $page; ?>/<?php echo $page_count ?> 页 记录:<?php echo $message_count;?> 条</td>
<td width="65%" align="right">
<?php
if($page!=1){
echo "<a href=pg.php?page=1>首页</a> ";
echo "<a href=pg.php?page=".($page-1).">上一页</a> ";
}
if($page<$page_count){
echo "<a href=pg.php?page=".($page+1).">下一页</a> ";
echo "<a href=pg.php?page=".$page_count.">尾页</a>";} ?>
</td>
</tr>
</table>
</body>
</html>
运行之后说:公告标题 公告内容
页次:/
Notice: Undefined variable: page_count in C:\xampp\htdocs\pg.php on line 44
页 记录:
Notice: Undefined variable: message_count in C:\xampp\htdocs\pg.php on line 44
条 首页 上一页
Notice: Undefined variable: page_count in C:\xampp\htdocs\pg.php on line 51
请大侠帮我看下
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>分页</title>
</head><body>
<table border="0">
<tr>
<td width="202" height="12">公告标题</td>
<td width="202">公告内容</td>
</tr>
<?php
$link=mysql_connect("localhost","root","");
mysql_select_db("by",$link);
mysql_query("set names gb2312");
if($page=""){
$page=1;}
if(is_numeric($page)){
$page_size=4;
$result=mysql_query("select count(*) as total from a order by id desc");
$messmge_count=mysql_result($result,0,"total");
$page_count=ceil($messmge_count/$page_size);
$offset=($page-1)*$page_size;
$sql=mysql_query("select * from a order by id desc limit $offset,$page_size");
$row=mysql_fetch_object($sql);
if(!$row){
echo "<font color='red'>暂无公告信息</font>";
}
do{
?>
<tr>
<td><?php echo $row->name; ?></td>
<td><?php echo $row->mima; ?></td>
</tr>
<?php
}while ($row=mysql_fetch_object($sql));
}
?>
</table>
<table width="667" height="30" border="0">
<tr>
<td width="37%" align="left"> 页次:<?php echo $page; ?>/<?php echo $page_count ?> 页 记录:<?php echo $message_count;?> 条</td>
<td width="65%" align="right">
<?php
if($page!=1){
echo "<a href=pg.php?page=1>首页</a> ";
echo "<a href=pg.php?page=".($page-1).">上一页</a> ";
}
if($page<$page_count){
echo "<a href=pg.php?page=".($page+1).">下一页</a> ";
echo "<a href=pg.php?page=".$page_count.">尾页</a>";} ?>
</td>
</tr>
</table>
</body>
</html>
运行之后说:公告标题 公告内容
页次:/
Notice: Undefined variable: page_count in C:\xampp\htdocs\pg.php on line 44
页 记录:
Notice: Undefined variable: message_count in C:\xampp\htdocs\pg.php on line 44
条 首页 上一页
Notice: Undefined variable: page_count in C:\xampp\htdocs\pg.php on line 51
请大侠帮我看下
if($page=""){
$page=1;}
改为
if($page==""){
$page=1;}
echo "<a href=pg.php?page=1>首页</a> ";
echo "<a href=pg.php?page=".($page-1).">上一页</a> ";
}
if($page<$page_count){
echo "<a href=pg.php?page=".($page+1).">下一页</a> ";
echo "<a href=pg.php?page=".$page_count.">尾页</a>";} ?>
这里的超链接有问题不能翻页请问怎么改
if($page==""){
...
应该这样写把
if($page==""){
$page = 1;
}
改成
$page = isset($_GET['page']) ? $_GET['page'] : 1;