见http://community.csdn.net/Expert/topic/4293/4293437.xml?temp=.1986658构造出那样的数组很容易的
select 字母, 人名 from 表然后在循环读出记录时
$ar[字母][child][] = 人名

解决方案 »

  1.   

    sql语句order by 第一个字母然后嵌套section就行了
      

  2.   

    我转贴过来吧:Smarty:php:
    <?php
         $ar = array(array('char' => 'A','child' => array(array('text' => 'aa'),array('text' => 'aaa'),)),
        
             array('char' => 'B','child' => array(array('text' => 'bb'),array('text' => 'bbb'),) ),
    );
        $tpl->assign("ar", $ar);
        $tpl->display('test.htm');
        
    ?> test.htm:
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=big5">
    <title></title>
    </head> 
    <body>
    <{section name=sec1 loop=$ar}>
    <{$ar[sec1].char}><br/>
    <{section name=sec2 loop=$ar[sec1].child}>
    <{$ar[sec1].child[sec2].text}><br/><{/section}>
    <{/section}></body>
    </html>是 阿辛的帖子。