Jason Shultz
Jason Shultz

Reputation: 970

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:

Upvotes: 1

Views: 192

Answers (1)

Stoosh
Stoosh

Reputation: 2429

$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.

Upvotes: 1

Related Questions