> -----Original Message-----
> From: Dan Rossi [mailto:[EMAIL PROTECTED] 
> Sent: Tuesday, August 07, 2007 7:20 AM
> To: Zend Framework
> Subject: [fw-general] Core paging functionality for Zend_Db
> 
> Hi i was wondering if there was any functionality yet for 
> paging with Zend_Db. 

You can use the "limitPage()" method in Zend_Db_Select.  I just noticed
that this method is not documented, which I will fix shortly (ZF-1824).

The limitPage() method is like using the LIMIT clause, but instead of
count and offset arguments, the arguments of limitPage() are page number
and rows per page.

Here's an example that fetches rows 20-29.  That is, the third page, if
pages are 10 rows each.

$select = $db->select()
  ->from('mytable')
  ->limitPage(3, 10);

> I was also wondering if there was a way 
> to have these paged results able to be split into columns of 
> 2 to 3 columns per row when fetchAll is called ? Currently I 
> have to do this which seem a bit clunky to me
> 
> $cols = 2;
>         $loop = ceil(count($results) / $cols);
>         $arr = array();   
>         for ($j=0;$j <= $loop;$j++) {
>             $arr[$j] = array_slice($results,$i,$cols);
>             $i = $i + $cols;
> }
> 

Do you mean row of database result set, or row of display?  Zend_Db
doesn't do anything regarding display, it just returns database result
sets.  It's possible to craft a SQL query to return sets of columns in
multiple rows, but it would be too awkward and inefficient to do this in
SQL.  It's better to handle this in your PHP code that formats the data
for display, as you are doing.  I'm not sure I understand from your code
what you want the output to be.

Regards,
Bill Karwin

Reply via email to