开发者

Alphabetize results in view

开发者_运维技巧I'm trying to do this in CodeIgniter. Here's my code I put into pastebin.

As you can guess, it's not working. I need the view to render the results like this:

  • A
  • A Client
  • A CLIENT 2
  • Another Client
  • B
  • Big Client
  • Brother client
  • C
  • Course I'm a Client
  • Coming Over Client


$prev_row = '';
foreach ($clients as $client) {
    $first_letter = strtoupper(substr($client['name'], 0, 1));
    if ($first_letter != $prev_row) {
        echo "<h3>$first_letter</h3>";
    }

    echo $client['name'] . "\n";
    $prev_row = $first_letter;
 }

Revised answer based on comments, not sure how your array is structured but this should point you in the right direction.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜