Thursday, November 15, 2012

Re: A somewhat interesting pagination problem

Thanks for the reply cricket, I'll try sortable and see if anything pops.

On Thursday, November 15, 2012 5:28:15 AM UTC+11, cricket wrote:
If a view is out then I think you're best bet is to keep the DB
records in the order you need and leave pagination to just limiting
the number. Have a look at the SortableBehavior. Perhaps you could
hack up a routine that ensures the records remain sorted properly even
as new ones are added.

On Wed, Nov 14, 2012 at 1:26 AM, char <charlo...@gmail.com> wrote:
> Hi all,
>
> I've got a problem which I hope is interesting to everyone.
>
> Got a generic table, in which each item has an image and an attribute that
> says wether the orientation is portriat or landscape.
>
> id int(10) unsigned NOT NULL
> namevarchar(255) NULL
> image varchar(255) NULL
> image_portrait tinyint(1) unsigned NOT NULL
>
> Now I need to paginate the results so that there are always 1 portrait
> images for every 2 landscape images.
>
> So if I wanted paginated results with limit of say 6, it should return the
> following:
>
> array(
>     (int) 0 => array(
>         'Item' => array(
>             'id' => '1',
>             'name' => 'container',
>             'image' => 'CH1.a.jpg',
>             'image_portrait' => '1'
>                 )
>     ),
>     (int) 1 => array(
>         'Item' => array(
>             'id' => '5',
>             'name' => 'container',
>             'image' => 'CH1.b.jpg',
>             'image_portrait' => '0'
>         )
>     ),
>     (int) 2 => array(
>         'Item' => array(
>             'id' => '13',
>             'name' => 'container',
>             'image' => 'CH21.c.jpg',
>             'image_portrait' => '0'
>         )
>     ),
>     (int) 3 => array(
>         'Item' => array(
>             'id' => '4',
>             'name' => 'container',
>             'image' => 'CH13.e.jpg',
>             'image_portrait' => '1',
>         )
>     ),
>     (int) 3 => array(
>         'Item' => array(
>             'id' => '24',
>             'name' => 'container',
>             'image' => 'CH19.jpg',
>             'image_portrait' => '0',
>         )
>     ),
>     (int) 3 => array(
>         'Item' => array(
>             'id' => '154',
>             'name' => 'container',
>             'image' => 'CH13.jpg',
>             'image_portrait' => '0',
>         )
>     ),
> )
>
> A few possibilities:
> - unioning portraits with landscapes to make sure the numbers match (limit x
> and limit 2x), but that is a lot of work with the built-in pagination (if
> possbile at all).
>
> - still paginate on the entire table and use that for the helper, on top of
> that, also paginate on landscapes (limit 2x/3) and portraits (limit x/3)
> seperately and use that to get the actual display data.
>
> - make the union a view then paginate on that, but the current hosting
> provider doesn't give me the privillage to create views...
>
> Any interesting solutions or suggestions?
>
> Cheers
> Char
>
> --
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
>
> ---
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To post to this group, send email to cake...@googlegroups.com.
> To unsubscribe from this group, send email to
> cake-php+u...@googlegroups.com.
> Visit this group at http://groups.google.com/group/cake-php?hl=en.
>
>

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
 
 

No comments: