Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在php中使用分页?_Php_Wamp - Fatal编程技术网

如何在php中使用分页?

如何在php中使用分页?,php,wamp,Php,Wamp,我需要为web应用程序使用php分页代码。有许多类可用于分页,下面是一个非常好的类: 有关更多信息,请参阅如何使用:部分:) 您可以对其进行编程。基本思想是从查询字符串中获取信息,然后使用它来显示某些数据。您是否从数据库中获取数据?以下是您需要注意/思考的几件事: $totalItems = 110; $itemsPerPage = 5; $pages = $totalItems / $itemsPerPage; $currentPage = $_GET['page']; for($i=

我需要为web应用程序使用php分页代码。

有许多类可用于分页,下面是一个非常好的类:

有关更多信息,请参阅如何使用:部分:)


您可以对其进行编程。基本思想是从
查询字符串中获取信息,然后使用它来显示某些数据。您是否从数据库中获取数据?以下是您需要注意/思考的几件事:

$totalItems = 110;
$itemsPerPage = 5;
$pages = $totalItems / $itemsPerPage;
$currentPage = $_GET['page'];

for($i=0;$i < $pages;$i++){
   echo "<a href=\"?page=$i\">$i</a> ";
}  
//Your query would look something like this once it was done:
//SELECT `data` FROM `table` OFFSET $currentPage-1 * $itemsPerPage,$currentPage * $itemsPerPage
$totalItems=110;
$itemsPerPage=5;
$pages=$totalItems/$itemsPerPage;
$currentPage=$_GET['page'];
对于($i=0;$i<$pages;$i++){
回声“;
}  
//完成查询后,您的查询将如下所示:
//从“表”中选择“数据”偏移量$currentPage-1*$itemsPerPage,$currentPage*$itemsPerPage
然后,您必须使用这些变量或类似的东西,使您的数据库查询获取正确的数据。

这里还有另一个: