Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Archive

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Problem with pagination


Reply

2 Posts   2176 Views

Avatar
OzziNL

16 April 2008 at 9:09am (Last edited: 16 April 2008 9:11am), Community Member, 37 Posts

Hello, I am trying to solve a problem with pagination for two days now! I'll explain:

//on a controller
   function showActivities() {
      
      isset($_GET['start']) ? $start = $_GET['start'] : $start = 0;
      
      $list = DataObject::get("ActiviteitPage", "","", "","{$start}," . AANTAL_ITEMS_ACTIVITEITENOVERZICHT );
         
      return ($list) ? $list : null;
   }

On the template:

       <!-- pagination -->
          <% if showActivities.MoreThanOnePage %>
           <div id="head_itc_file">
           <% control showActivities.Pages %>
              <% if CurrentBool %>
                 <img src="/themes/inventheon/images/file_itc.gif" alt="" />
              <% else %>
                 <a href="$Link"><img src="/themes/inventheon/images/file_off_itc.gif" alt="" /></a>
              <% end_if %>
           <% end_control %>
           </div>
          <% end_if %>
       <!-- end pagination -->
//...cut
$ActiviteitenLijst.Count //PRINTS 3
<% include ActiviteitenLijst %> //PRINTS 3 ITEMS

Now the problem: The pagination returns pages for 107 items. Whatever the numer of items per page, it is based on 107 item (1 -> 107 pages, 10 -> 11 pages )

looking in the code I see the problem comes from:

$this->setPageLimits($start, $length, $query->unlimitedRowCount());


The last parameter is 107 and should be 5 (there are 5 ActiviteitPage items)

Now: it gets odd:

in this code in SQLQuery.php:

   function unlimitedRowCount( $column = "*" ) {
      $clone = clone $this;
      $clone->select = array("count($column)");
      $clone->limit = null;
      $clone->orderby = null;
      $clone->groupby = null;
      Debug::show($clone); // THIS DUMP LINE!!!!!!!!!!!!!!!!!!!!!!!!!!!
      $queryContent = singleton('SiteTree')->extendedSQL();
      return $queryContent->execute()->value();
   }


The dump line prints:

SQLQuery::__set_state(array( 'select' => array ( 0 => 'count(*)', ), 'from' => array ( 'SiteTree' => '`SiteTree_Live`', 'InventheonPage' => 'LEFT JOIN `InventheonPage_Live` ON `InventheonPage_Live`.ID = `SiteTree_Live`.ID', 'ActiviteitPage' => 'LEFT JOIN `ActiviteitPage_Live` ON `ActiviteitPage_Live`.ID = `SiteTree_Live`.ID', ), 'where' => array ( 0 => '`SiteTree_Live`.ClassName IN (\'ActiviteitPage\')', ), 'orderby' => NULL, 'groupby' => NULL, 'having' => NULL, 'limit' => NULL, 'distinct' => NULL, 'delete' => NULL, 'extension_instances' => array ( ), 'class' => 'SQLQuery', ))


I translate it myself to sql and that is:

SELECT count(*)
FROM SiteTree_Live
LEFT JOIN `InventheonPage_Live` ON `InventheonPage_Live`.ID = `SiteTree_Live`.ID
LEFT JOIN `ActiviteitPage_Live` ON `ActiviteitPage_Live`.ID = `SiteTree_Live`.ID
WHERE `SiteTree_Live`.ClassName IN ('ActiviteitPage')


And when I run it: 5 !!!!!!

But the function SQLQuery::unlimitedRowCount() returns 107

Please any help!!!
I don't understand this anymore...

Thanks,
Oscar

Avatar
OzziNL

16 April 2008 at 10:06pm Community Member, 37 Posts

Case closed!
Don't know how this code became as pasted but this function is not like the function in the Stable.