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

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

Jun 13, 2016 pm 01:36 PM
echo gt lt page quot

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 "下一页  最后一页 &nbsp";
}
else 
{
echo "下一页";
echo " ";
echo "最后一页";
echo $page_count;
}

?>

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

------解决方案--------------------
$page=$_GET['page'] ? $_GET['page'] : 1; //加上这句。
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

Hot Article

Hot Article

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What are the differences between Huawei GT3 Pro and GT4? What are the differences between Huawei GT3 Pro and GT4? Dec 29, 2023 pm 02:27 PM

What are the differences between Huawei GT3 Pro and GT4?

Fix: Snipping tool not working in Windows 11 Fix: Snipping tool not working in Windows 11 Aug 24, 2023 am 09:48 AM

Fix: Snipping tool not working in Windows 11

Five selected Go language open source projects to take you to explore the technology world Five selected Go language open source projects to take you to explore the technology world Jan 30, 2024 am 09:08 AM

Five selected Go language open source projects to take you to explore the technology world

Go language development essentials: 5 popular framework recommendations Go language development essentials: 5 popular framework recommendations Mar 24, 2024 pm 01:15 PM

Go language development essentials: 5 popular framework recommendations

How to Fix Can't Connect to App Store Error on iPhone How to Fix Can't Connect to App Store Error on iPhone Jul 29, 2023 am 08:22 AM

How to Fix Can't Connect to App Store Error on iPhone

Implementing distributed task scheduling using Golang's web framework Echo framework Implementing distributed task scheduling using Golang's web framework Echo framework Jun 24, 2023 am 11:49 AM

Implementing distributed task scheduling using Golang's web framework Echo framework

Laravel development: How to implement WebSockets communication using Laravel Echo and Pusher? Laravel development: How to implement WebSockets communication using Laravel Echo and Pusher? Jun 13, 2023 pm 05:01 PM

Laravel development: How to implement WebSockets communication using Laravel Echo and Pusher?

Detailed explanation of the role and usage of the echo keyword in PHP Detailed explanation of the role and usage of the echo keyword in PHP Jun 28, 2023 pm 08:12 PM

Detailed explanation of the role and usage of the echo keyword in PHP

See all articles