Re: list items per page and pagination

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

By 4cdg - August 8, 2013

In response to: [url "http://www.interactivetools.com/forum/forum-posts.php?postNum=2211818#post2211818"]Re: [ikanizaj] list items per page and pagination[/url], ...

I am having a similar issue with pagination.

I am using 2 separate list viewers to create a viewer with 2 different layouts.  First calls 3 records into 1 row, 3 columns like this

// load records from 'listings'
  list($listingsRecords, $listingsMetaData) = getRecords(array(
    'tableName'   => 'listings',
'orderBy'     => $orderBy,
'perPage'     => '3',
    'loadUploads' => true,
  ));

Next i want to call next 7, 1 record per row
then have pagination to go to next page and repeat the layout
3 records in 1 row --- 7 records, 1 per row.

Now the call above works, but the second call below calls the rest of the records down the page

// load records from 'listings'
  list($listings2Records, $listings2MetaData) = getRecords(array(
    'tableName'   => 'listings',
'orderBy'     => $orderBy,
'offset'     => 3,
    'loadUploads' => true,
  ));

how can i accomplish this, you can see what i have at at this link

http://www.searcharental.com/listings.php?address%2Ccity%2Czip_code%2Cstate_query=&rent_per_month_min=&rent_per_month_max=&category=&bedrooms_min=&bedrooms_max=&bathrooms_min=&bathrooms_max=&type%2Cschool%2Cdeposits_or_fees%2Clength_of_contract%2Cdescription%2Cfeatures_amenities_query=&x=81&y=15

after the 10th record, i want the pagination... 

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