Group PHP results on first letter of name

后端 未结 6 1367
粉色の甜心
粉色の甜心 2020-12-10 17:25

I have a query which gets all records ordered by last_name. Now I would like to create a loop that groups these results by the first letter of the last name and display the

6条回答
  •  时光说笑
    2020-12-10 17:48

    In your view you could then loop the records and split them up:

    $current = '';
    foreach ($rows as $r) {
        if (!$current || strtolower($r['name'][0]) != $current) {
            $current = strtolower($r['name'][0]);
            echo strtoupper($current).'
    ---------------'; } echo $row['name'].'
    '; }

提交回复
热议问题