Looking for a solid way to let users choose the number of records shown per page

8 posts by 3 authors in: Forums > CMS Builder
Last Post: May 6, 2014   (RSS)

By rconring - May 5, 2014

I just did that yesterday for a product listing.  It can be done many ways, but I chose to have a field in my site config record  called Products Per Page and is a dropdown with 5 10 15 20 etc as choices.  Then, in the product viewer, I changed the per page constant to the variable.

  list($productsRecords, $productsMetaData) = getRecords(array(
    'tableName'   => 'products',
    'where'       => "category = $pageNum",    
    'perPage'     => $common_infoRecord['products_per_page'],
    'loadUploads' => true,
    'allowSearch' => false,
  ));

Is that what you need?

Ron Conring
Conring Automation Services
----------------------------------------
Software for Business and Industry Since 1987

By HDLLC - May 5, 2014

Yes!  That sounds like what i am looking for.  I think I understand how you did that...  I will dig around and see if I can reproduce it! 
If you have any additional info - please post, otherwise, i'm going to work on that after lunch!
Thanks!  --Jeff

By Damon - May 5, 2014

Hi,

Here is one example of a way to change the number of records that display.

Above the "load records" code on your page add something like this:

 $perPage = '10';   //default number of records to display
 if (@is_numeric($_REQUEST['perpage'])) 
    { $perPage =  $_REQUEST['perpage']; }

I used the is_numeric function to prevent anything but numbers from being passed in.

Now in you "load records" code add this:

'perPage'     => $perPage,

So now you can pass in values in the URL like this:
http://example.com/records.php?perpage=15

And 15 records will be displayed.

The last step is to create a form with a dropdown list of the per page options and pass the "perpage" value back to the same page.
Hope this helps.

Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By rconring - May 5, 2014

OOOPS!  Sorry, I didn't catch the word USERS.  The code I gave you allows the ADMIN to set the records per page.  To allow the user to dynamically change records per page is a tad more complex.  I did that on a site a while back ... just need to dig up the code.

Ron Conring
Conring Automation Services
----------------------------------------
Software for Business and Industry Since 1987

By HDLLC - May 5, 2014

Thanks fellas!  I think I am on the right path now!  Gonna give this a whirl and see how it goes.  Thanks again!

By HDLLC - May 6, 2014

Thanks a ton!  I'm into this, and I think i'm fairly solid - but one question...
How would I handle "show all records" instead of limiting to just 10, 24, 48, etc. per page...?

Thanks in advance!

--Jeff

By rconring - May 6, 2014

Add a "Show All" choice with a value of zero or NULL.

Ron Conring
Conring Automation Services
----------------------------------------
Software for Business and Industry Since 1987