Joomla Infinite Scrolling mysql pagination issues - php

I have set up infinite scrolling on a Joomla based website to load db results from mysql query. It works fine but when I have it set up to load 10 results at a time, it skips results 11-20 and then loads the rest of the values, and likewise when I set up to show 20 results it loads the first 40 without any repeats, and then proceeds to load 10 previouss results and 10 new ones for each new pagination result until it reaches the end of the list. Here is the code I have for pagination,
//
jimport('joomla.html.pagination');
// prepare the pagination values
$total = $this->xyz->getTotal('posts',' and cat_id = ' . $cat->cat_id);
$limit = $mainframe->getUserStateFromRequest('global.list.limit','limit', $mainframe->getCfg('list_limit'));
$limitstart = $mainframe->getUserStateFromRequest(JRequest::getVar('option').'limitstart','limitstart', 0);
$this->items = $this->xyz->categoryItems(JRequest::getInt('cat_id'),$limitstart,$limit);
// create the pagination object
$_pagination = new JPagination($total, $limitstart,$limit);
$_pagination_footer = $_pagination->getListFooter();
//
I should mention that I set the $limit value to 10 on line 7 of the code above to make it load 10 at a time. If it is left as $limit it loads 20 at a time.
Preferably I would like to load 50 at a time without any repeats or omissions but as it is now, I get plenty of repeats when set to 50. I found that setting it to 10 gives me the best results but still skips 11-20.
Any suggestions or thoughts would be greatly appreciated.

Had similar problems on two different occasions
1) SEF turned off
You might want to debug global.list.limit to check for consistency in values it loads
2) SEF turned on
Look for inconsistent entries in the redirection base for the same sef url.

Related

Only load next section if previous section has finished paginating in Laravel (Multi Level Paging)

The Issue
Consider the following layout:
Now imagine that each section within the above list, is retrieved by an entirely separate query on the database...
The content on the page is paginated as the user scrolls (lazy loading). Resultantly, each section is only visible once the previous section has been completely loaded like so:
For the purposes of the following example, please assume the following:
Page size is 5
Section 1 has 6 items
Section 2 has 10 items
GET api.example.com/some_request?page=1
{
data: {
'section_1': [
// The first 5 items of section 1 are returned
]
},
laravel_pagination_stuff_etc...
}
GET api.example.com/some_request?page=2
{
data: {
'section_1': [
// The last item of section 1 is returned
],
'section_2': [
// The first 4 items of section 2 are returned
]
},
laravel_pagination_stuff_etc...
}
What I have tried
I have played around with Laravel Pagination like so:
// Determine which page to retrieve
$page = Input::get('page', 1);
$paginate = 5;
// Paginate the results
$offset = ($page * $paginate) - $paginate;
$items_for_current_page = array_slice($results, $offset, $paginate, true);
$results = new \Illuminate\Pagination\LengthAwarePaginator($items_for_current_page, count($results), $paginate, $page);
However, I am not familiar enough with the framework and library so before I spend hours/days going through the Laravel Pagination code, are there any Laravel pro's out there that can see a way to achieve the above in a simple way?
Additional Information
Just to be clear as to what I am asking; I am looking for a possible way to group and paginate two entirely separate queries into one page parameter. Is this possible?
Please note I am not asking, nor do I need, the code written for me. I am merely asking for a bit of guidance in the right direction in regards to the logic and the code.

Propel paginate() method doesn't work as expected

I'm trying to do a pagination in the website I'm developing. I found that Propel has a paginate() method that is useful for doing this but I cannot make it work.
Here's some code:
$pager = ElementQuery::create()->paginate($page = 1, $maxPerPage = 10);
$pager should have the following methods, by Propel's official documentation:
$pager->getNbResults(); // total number of results if not paginated
$pager->haveToPaginate(); // return true if the total number of results exceeds the maximum per page
$pager->getFirstIndex(); // index of the first result in the page
$pager->getLastIndex(); // index of the last result in the page
And I should be able to do something like this:
$links = $pager->getLinks(5);
But I'm just getting Element class methods.
Am I missing something?
Here's where I got that information about pagination (to find it fast press Ctrl + F and type paginate())
Thanks.
If you let me auto-answer my question... It seems those methods I mentioned are there, but for some reason they don't appear on my Netbeans editor when I write $pager->
I don't know if this counts as an answer but the "problem" is "solved"...

Magento get numerical order of products in collection

In product/list.phtml I'm attempting to get the number of each product as it would appear in the view to the user. Let's say a category has 24 products. If the user proceeds to page two, the first product would be 17 (and the toolbar pager will show 17-24 of 24 Products). I am trying to get that first number.
My issue is that I cannot get an accurate numerical listing. The toolbar pager calculates and displays the correct product numbers currently being viewed, I thought I would just try calling the block and getting the information from it. I figured it would be as simple as calling:
$pager = Mage::getBlockSingleton('page/html_pager')->getFirstNum();
That returns the error Fatal error: Call to a member function getPageSize() on a non-object in /app/code/core/Mage/Page/Block/Html/Pager.php on line 192.
That points to this function, the return statement is line 192:
public function getFirstNum()
{
$collection = $this->getCollection();
return $collection->getPageSize()*($collection->getCurPage()-1)+1;
}
Digging further it appears that the pager block needs to have a collection set before it can do any operations. So I set the collection and hope it works:
$_productCollection=$this->getLoadedProductCollection();
$pager = Mage::getBlockSingleton('page/html_pager')->setCollection($_productCollection)->getFirstNum();
Now I'm getting output, but pageSize is set to 10, which is causing the advancement of the numbers to be different (and incorrect) from the toolbar pager. In the Admin Panel I have Grid and List default Products per Page set to 16 which is what I was expecting it to be and that is the number the toolbar pager is operating on.
What do I need to do to get a correct and accurate numerical listing?
It is just a guess, but give it a try:
Replace:
$pager = Mage::getBlockSingleton('page/html_pager')->setCollection($_productCollection)->getFirstNum();
with:
$pager = Mage::getBlockSingleton('page/html_pager')->setCollection($_productCollection)->setPageSize(16)->getFirstNum();
If curPage isn't set correctly you can try ->setCurPage($your_page_variable) after setPageSize(16).

CodeIgniter pagination url page number

From what I saw, CodeIgniter's pagination is counting the page wrong way, because I got pagination looking like this:
1 2 3 >
And its good, the problem is in the each pagination number url, except the first one:
Number 2 from the pagination has the following url:
http://my-url.com/index.php/page/1
And number 3 has the following url:
http://my-url.com/index.php/page/2
So, the number is URL is decreased by 1 everytime.
How can I solve that, so the page numbers in urls will be the same as the page numbers in the pagination?
My pagination config:
$config['per_page'] = 5;
$config['base_url'] = site_url('page');
$config['uri_segment'] = 2;
$page = $this->uri->segment(2);
$total_rows_array = $this->records->get($config['per_page'], $page * $config['per_page']); // parameters: limit, offset.
$config['total_rows'] = count($total_rows_array);
Had the same problem you have, and I added this configuration line:
$config['use_page_numbers'] = TRUE;
and it works like a charm!
Are you using page numbers in the pagination config?
The way CodeIgniters pagination works (by default) is that you set the number of records to show in the code, CodeIgniter works out the offset and appends that to the URL.
The reason page 1 (if you will) has no number at the end is because there is no offset, page 2 will have an offset of 1 because it is offsetting that many records. Wow this is a lot harder to explain than I thought before I started typing this answer!
:EDIT:
Also, if you are using page numbers in the pagination config, I imagine that code igniter is taking the per_page amount and multiplying it by the page number to get the real offset for the records.
Page 2 would really work out as per_page (15) * page_number (1) = 15 for the real offset.

How can I create a RSS feed with a limit statement in wordpress

I am basically creating an iphone app that get's it's data from wordpress. Wordpress will serve audio and video links via a RSS feed to the iphone app. I have the feed and audio player working great but can't seem to find anything related to how to create a custom feed where I can specify pagination like start=0&items=10. A plugin would be great but I can code something up in PHP if anyone has any ideas.
I'm going to answer this question by changing the standard RSS feed of a WordPress installation to respond to limits passed by query parameters. As you say you've already got a working feed, this should hopefully give you everything else you need.
By default, the standard feeds in WordPress are limited by the setting "Syndication feeds show the most recent X items" on the Settings→Reading page, and are unpaginated, as that wouldn't generally make sense for an RSS feed. This is controlled by WordPress's WP_Query::get_posts() method, in query.php, if you're interested in taking a look at how things work internally.
However, although the feed query's limit is set to LIMIT 0, X (where X is the above setting, 10 by default) , you can override the limit by filtering the query in the right place.
For example, the filter post_limits will filter the LIMIT clause of the query between the point it's set up by the default code for feeds and the time it's run. So, the following code in a plugin -- or even in your theme's functions.php -- will completely unlimit the items returned in your RSS feeds:
function custom_rss_limits($limits) {
if (is_feed()) {
// If this is a feed, drop the LIMIT clause completely
return "";
} else {
// It's not a feed; leave the normal LIMIT in place.
return $limits;
}
}
add_filter('post_limits', 'custom_rss_limits');
(At this point I should mention the obvious security implications -- if you've got 20,000 posts on your blog, you'll cause yourself a lot of server load and bandwidth if if lots of people start grabbing your feed, and you send out all 20,000 items to everyone. Therefore, bear in mind that whatever you end up doing, you may still want to enforce some hard limits, in case someone figures out your feed endpoint can be asked for everything, say by analysing traffic from your iPhone app.)
Now all we've got to do is to respond to query parameters. First of all, we register your two query parameters with WordPress:
function rss_limit_queryvars( $qv ) {
$qv[] = 'start';
$qv[] = 'items';
return $qv;
}
add_filter('query_vars', 'rss_limit_queryvars' );
That allows us to pass in the start and items variables you're suggesting for your URL parameters.
All we have to do then is to adjust our original LIMIT changing function to respond to them:
function custom_rss_limits($limits) {
if (is_feed()) {
global $wp_query;
if (isset($wp_query->query_vars['start']) &&
isset($wp_query->query_vars['items'])) {
// We're a feed, and we got pagination parameters. Override our
// standard limit.
// First convert to ints in case anyone's put something hinky
// in the query string.
$start = intval($wp_query->query_vars['start']);
$items = intval($wp_query->query_vars['items']);
$limits = "LIMIT $start, $items";
} else {
// We weren't passed pagination parameters, so just
// leave the default limits alone.
}
}
return $limits;
}
add_filter('post_limits', 'custom_rss_limits');
And there you go. Throw those last two blocks of code at WordPress, and you can now use a URL like this on any of your existing feeds:
http://example.com/feed/?start=30&items=25
For this example, you'll get the normal RSS feed, but with 25 items starting from item number 30.
...and if you don't pass the query parameters, everything will work like normal.

Categories