开发者

group table entries alphabetically and have a link for each letter A B C and so on

I have a table which holds the names of loads of charities in the UK.

I want to have a page which will allow users to search through these charities but there's 1000s of them. I'd like to be able to have the alphabet written out A, B, C and so on with each letter a link to all the charities beginning with that lett开发者_StackOverflow中文版er.

Whats the best way to go about doing that using cakephp?


Pendo is right but you'll get all alphabet. You should show only the letters which have content:

$words = $this->Word->find('all');
$letters = array();
foreach ($words as $word) {
    $letters[] = substr($word['Word']['Title'], 0, 1);
}
$letters = array_unique($letters);
sort($letters);
$this->set(compact('letters'));


Not sure how CakePHP works, but basically in PHP what you would do is:

1) Looping the alphabet:

for ($i=65; $i<=90; $i++) {
  echo chr($i);
}

Ofcourse you should add the right link yourself.

2) If a letter is chosen get it from a POST/GET request and use it in a query:

SELECT fields FROM table WHERE field LIKE 'X%';

X stands for the chosen letter.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜