The most efficient way database-wise would be to have a char(1)
database column that you populate with whatever the first letter of
the field you're using... that way it could be indexed and easily
counted. It would be slightly slower when saving data but (I assume)
much faster retrieving it.


If you didn't want to do that, you could use the mysql substring
function:

Here is mysql the query string(tested)
SELECT SUBSTRING(name, 1, 1) as letter, COUNT(SUBSTRING(name, 1, 1))
as count FROM people GROUP BY letter ORDER BY letter;

Here is a cake query(untested)
$this->People->find('list', array(
                'fields' => array('SUBSTRING(name, 1, 1) as letter',
'COUNT(SUBSTRING(name, 1, 1)) AS COUNT'),
                'group' => 'letter',
                'order' => array('letter' => 'ASC')
                )
);

On Sep 3, 4:02 pm, "Dave Maharaj" <m...@davemaharaj.com> wrote:
> Sorry , my first thought would be to do a looping find->first of each letter
> and so if it found a record starting with A set that link true, if nothing
> for B then just the letter no link and co on...
>
> The only  problem I see is 26 queries just to build the paging links.
>
> Other ideas?
>
> Thanks
>
> From: Dave Maharaj [mailto:m...@davemaharaj.com]
> Sent: September-03-10 6:22 PM
> To: cake-php@googlegroups.com
> Subject: Alternate Pagination question
>
> Has anyone created,  thought of , started on the idea of an alphabetical
> character paging system?
>
> So rather than 1 | 2 | 3 it spits out A |B |C?
>
> The ABC part seems rather simple just getting the letters to be links if
> there are records for that letter seems to be the real issue. Any ideas on
> how to approach this one before I start?
>
> Thanks,
>
> Dave
>
> Check out the new CakePHP Questions sitehttp://cakeqs.organd help others
> with their CakePHP related questions.
>
> 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+unsubscr...@googlegroups.com For more options, visit this group 
> athttp://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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

Reply via email to