Home > Backend Development > PHP Tutorial > php和mysql关于分页的有关问题

php和mysql关于分页的有关问题

WBOY
Release: 2016-06-13 10:15:41
Original
875 people have browsed it

php和mysql关于分页的问题
用php提取mysql中的信息,把他分页显示
代码:




$mylink=mysql_connect("localhost","root","998121021");
mysql_select_db("liuyan",$mylink);
$sql="select * from data order by time";
$result=mysql_query($sql);

$message_count=mysql_num_rows($result);
echo $message_count;
$i=$message_count-1;
$page_size=2;
$page_count=ceil($message_count/$page_size);
echo $page_count;
if($page if($page>$page_count) $page=$page_count;
$offset=($page-1)*$page_size;
$sql1="select * from data order by time limit $offset,$page_size";
$result1=mysql_query($sql1);


while($myarray=mysql_fetch_array($result1)){
extract($myarray);
echo '';
echo '';
echo '';
echo '';
echo '';
echo '';
echo '';
echo '';
echo '';
echo '';
echo '';
echo '';
echo '';
$i--;
}



?>

'.($message_count-$i)."楼".''."用户名:".$name.''.''.$email.'
'.$time.'
'.$words.'
'.'
'.'


$pre_page=$page-1;
$next_page=$page+1;
echo $page;
$PATH_INFO=pathinfo("http://localhost:250/myphp编程/留言板的分页显示/留言板分页显示.php");
if($page==1)
{
echo "第一页  上一页"."  ";
}
else 
{
echo "第一页";
echo " ";
echo "上一页";
}
echo " ";
if($page==$page_count)
{
echo "下一页  最后一页  ";
}
else 
{
echo "下一页";
echo " ";
echo "最后一页";
echo $page_count;
}

?>

代码的分页显示部分是错误的,书上的path_info()函数用错了,我也不知道怎么用,“http://localhost:250/myphp编程/留言板的分页显示/留言板分页显示.php”是我的文件路径。请问在“下一页”“最后一页”,“第一页”“前一页”的链接是应该怎么写?

------解决方案--------------------
$page=$_GET['page'] ? $_GET['page'] : 1; //加上这句。
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template