Re: list items per page and pagination

3 posts by 2 authors in: Forums > CMS Builder
Last Post: August 8, 2013   (RSS)

By gregThomas - August 8, 2013

Hi,

If you're trying to load 10 records total, and then break it up so that 3 record are displayed at the top, and the next 7 are displayed below, I would just use one getRecords call and then break up which records are displayed where:

<?php
  // load records from 'listings'
  list($listingsRecords, $listingsMetaData) = getRecords(array(
    'tableName'   => 'listings',
    'orderBy'     => @$orderBy,
    'perPage'     => '10',
    'loadUploads' => true,
  ));
 
  //load the first 3 records into a seperate array
  $topHouses    = array_slice($listingsRecords, 0, 3);
  //Load all of the other records into sepereate array
  $bottomHouses = array_slice($listingsRecords, 4, 10);
?>
  <!-- display the first 3 records -->
  <div id="topDiv">
    <ul>
      <?php foreach($topHouses as $house): ?>
        <li><?php showme($house); ?></li>
      <?php endforeach; ?>
    </ul>
  </div>
  <!-- display the last 7 records -->
  <div id="bottomDiv">
    <ul>
      <?php foreach($bottomHouses as $house): ?>
        <li><?php showme($house); ?></li>
      <?php endforeach; ?>
    </ul>
  </div>

This is just example code, so you'll have to make few changes to get it working with your site.

So the getRecords gets the 10 records that need to be displayed on the current page, then the array slice function is used to split the array into two new arrays, one that contains the top 3 houses, and one that contains the bottom 7 houses. Then you just have to add pagination to the page (the code generator that comes with CMSB can be used to generate pagination). 

Let me know if you have any questions.

Cheers!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By 4cdg - August 8, 2013

perfect

thanks so much