简体   繁体   English

php 分页问题怎么办?

[英]php how to do pagination problem?

i am trying to do some pagination for my website and i'm using this tutorial and i run in a few problems.我正在尝试为我的网站做一些分页,我正在使用本教程,但遇到了一些问题。

first, this is how i find out the total nr of results:首先,这就是我找出结果总数的方法:

$total_records_left = 'SELECT COUNT(*) FROM `comments` WHERE `post_id_fk` = 1';
$results_left = mysql_query($total_records_left) or die('Sorry, we could not count the number of results: ' . mysql_error());
$numberofresults_left = mysql_result($results_left, 0);

$numberofresults_left will return lets say 20 records $numberofresults_left将返回20 records

now, if i fallow the tutorial, at one point i see that i need to declare this vars:现在,如果我放弃本教程,有一次我看到我需要声明这个变量:

$pages = new Paginator;  
$pages->items_total = $num_rows[0];  
$pages->mid_range = 9;  
$pages->paginate();  
echo $pages->display_pages();  

I don't understand how to connect my $numberofresults_left with those vars.我不明白如何将我的$numberofresults_left与这些变量连接起来。 How is the paginator.class.php is gonna know how many pages do i have? paginator.class.php 如何知道我有多少页?

also i see this query at one point: SELECT title FROM comments WHERE title != '' ORDER BY title ASC $pages->limit but there is no variable connected to it.我也曾一度看到此查询: SELECT title FROM comments WHERE title != '' ORDER BY title ASC $pages->limit但没有与之相关的变量。 Where i am gonna use this?我要在哪里使用这个?

Please make me understand how this actually works Thanks请让我了解这实际上是如何工作的 谢谢

I think you've got a couple variables mixed up.我认为您混淆了几个变量。 $numberofresults_left looks as though it should be called $num_rows . $numberofresults_left看起来好像应该称为$num_rows As for the latter part of your question, $pages is the instance of the Paginator class, and ->limit is the public property that records the limit when the object was created.至于你问题的后半部分, $pages是 Paginator class 的实例, ->limit是记录 object 创建时的限制的公共属性。

Towards the end of the article you're following, you should read the following:在您关注的文章即将结束时,您应该阅读以下内容:

$pages->limit is critical in making everything work and allows our paginator object to tell the query to fetch only the limited number of records that we need. $pages->limit对使一切正常运行至关重要,它允许我们的分页器 object 告诉查询只获取我们需要的有限数量的记录。 For example, if we wanted to see page seven of our data, and we're viewing 25 items per page, then $pages->limit would be the same as LIMIT 150,25 in SQL.例如,如果我们想查看数据的第 7 页,并且每页查看 25 个项目,则$pages->limit将与 SQL 中的LIMIT 150,25相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM