Skip navigation

Let’s say you have a store table in your database and you want to get the first letter of each store’s name. So you can create a menu by first letter of each store name and not having a letter that contains no stores.

1
2
3
4
5
$stores = $this->Store->find('all',array(    'order'=>'name ASC',
'fields'=>'DISTINCT(UPPER(LEFT(name,1))) AS letter',
'conditions'=>array("UPPER(LEFT(name,1)) REGEXP '[A-Z]'")));

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>