Pagination issues

4 posts by 2 authors in: Forums > CMS Builder
Last Post: September 11, 2014   (RSS)

By Jesus - September 10, 2014

Hi everyone. I've been done similar stuff before but I just can't figure it out right now. I hope anyone around can give me a hand with this pagination issue.

On my header I've this. I set the limit to 2 so I can test the pagination.

  // load records from 'demo_stuff'
  list($demo_stuffRecords, $demo_stuffMetaData) = getRecords(array(
    'tableName'   => 'demo_stuff',
    'loadUploads' => true,
    'allowSearch' => true,
    'limit'       => '2', 
  ));

Now, on my website I'm using this:

<!-- PAGINATION -->
<div class="row">

<div class="col-md-12 responsive-text-center text-center">
<!-- Display Page Links (Paste anywhere below "Load Record List") -->
    <?php   
       if (@!$_GET['page']): $current_page = "1";  
        else: $current_page = $_GET['page'];     
       endif;
     ?>  
                            
  <?php  
  $startNumber = max($current_page - 2, 1);  
  $endNumber   = min($current_page + 2, $demo_stuffMetaData['totalPages']);  
  ?> 
 

<ul class="pagination">
<?php if ($demo_stuffMetaData['prevPage']): ?> 
<li><a href="<?php echo $demo_stuffMetaData['prevPageLink'] ?>"><i class="fa fa-chevron-left"></i></a></li>
  <?php if ($startNumber > '1'): ?> 
  <li><a href="?<?php echo http_build_query(array_merge($_REQUEST, array( 'page' => '1' ))) ?>">1</a></li>
  <?php endif ?>  
  <?php else: ?> 
  &nbsp;   
  <?php endif ?>  

<?php foreach (range($startNumber,$endNumber) as $page): ?> 
  
  <?php if ($page == $current_page): ?>
  <li class="active"><?php echo $page; ?></li>  
  <?php else: ?>
  <li><a href="?<?php echo http_build_query(array_merge($_REQUEST, array( 'page' => $page ))) ?>"><?php echo $page; ?></a></li>  
  <?php endif ?>  
  <?php endforeach; ?>  


  <?php if ($demo_stuffMetaData['nextPage']): ?> 
  <?php if ($demo_stuffMetaData['totalPages'] > $endNumber): ?> 
  ... <li><a href="?<?php echo http_build_query(array_merge($_REQUEST, array( 'page' => $demo_stuffMetaData['totalPages'] ))) ?>"><?php echo $demo_stuffMetaData['totalPages'];?></a></li>
  <?php endif ?>
  <li><a href="<?php echo $demo_stuffMetaData['nextPageLink'] ?>"><i class="fa fa-chevron-right"></i></a></li>  
  <?php else: ?>    
  &nbsp;   
  <?php endif ?>

</ul>
</div>

</div>
<!-- /PAGINATION -->

I've 5 records on my table, and I'm just getting page 1 with 2 records on it. No other pages are being showed.

Probably too much code lately, but I just can't figure it out... I'm sure I'm missing something :p

Thanks for the help!

By claire - September 10, 2014

Hey there - you need to set the perPage variable in the getRecords query, for a start.

// load records from 'demo_stuff'
  list($demo_stuffRecords, $demo_stuffMetaData) = getRecords(array(
    'tableName'   => 'demo_stuff',
    'loadUploads' => true,
    'allowSearch' => true,
    'perPage'     => '2', 
  ));

Change the limit to perPage and then take a look at the pagination.

--------------------

Claire Ryan
interactivetools.com

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

By claire - September 11, 2014

Looks like a CSS issue. Not sure I can help you with that, unfortunately. 

I have a few code snippets for pagination if you want to try that instead.

--------------------

Claire Ryan
interactivetools.com

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