Wednesday, April 1, 2009

Re: Paging with aplhabetical search, not only by page number

I have something which does that. But it displays all names for a
given letter, rather than using a paging limit. I can't figure out a
clean way to do both.

public function index($letter = null)
{
$letter = is_null($letter) ? 'a' : strtolower((string) $letter);

$this->set('members', $this->Member->findByLetter($letter));
$this->set('alpha_list', $this->Member->getAlphaList());
$this->set('letter', $letter);

/* render the element only so we don't end up with a nested mess
*/
if ($this->RequestHandler->isAjax())
{
Configure::write('debug', 0);
$this->viewPath = 'elements'.DS.'members';
$this->render('alpha_list');
}
}

Member::findByLetter() uses this condition:

"lower(left(Member.last_name, 1)) = '${letter}'"

I avoided using LIKE because I only want to look at the first letter, anyway.

The rest is a bit more complicated, so I've posted it here:

http://bin.cakephp.org/view/1433101916

This is all based on some stuff I had with a non-Cake site. That one
actually had a lot of the heavy lifting done in the DB using pl/python
(Postgres).

On Wed, Apr 1, 2009 at 3:52 AM, meximex <meixnerit@gmail.com> wrote:
>
> hi,
> if i have an application with a list of 1000 items and want to jump to
> the page of the items starting with M. how could y do that?
>
> do i have to implement that by my self?
>
> if you would do it by yourself, how would you do it?
>
> create a loop for every letter and an sql that counts the items before
> that letter?
>
> isnt there something better in mysql?
>
>
> thx for your help!
> meximex
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: