Php 如何创建A-Z列表

Php 如何创建A-Z列表,php,codeigniter,foreach,Php,Codeigniter,Foreach,我正在使用Eclipse和CodeIgniter。我试图创建一个A-Z搜索页面,按字母表中的字母分组,但我不能用CodeIgniter 型号: 公共函数列表arlojas(){ $this->db->order_by(“nome_loja”、“ASC”); 返回$this->db->get(“lojas”)->result_array(); } 控制器: $dados['lojas']=$this->lojas_model->listarLojas(); 视图: (这是我的问题,我无法使fo

我正在使用Eclipse和CodeIgniter。我试图创建一个A-Z搜索页面,按字母表中的字母分组,但我不能用CodeIgniter

型号:

公共函数列表arlojas(){
$this->db->order_by(“nome_loja”、“ASC”);
返回$this->db->get(“lojas”)->result_array();
}
控制器:

$dados['lojas']=$this->lojas_model->listarLojas();
视图:

(这是我的问题,我无法使
foreach
显示为示例链接:)

HTML:


按字母顺序排列我们的主要商店
1 2 3 4 5 6 7 8 9 A B C D F G H I J K L M N O P Q R S T U V W Y X Z
A.
    试验

CSS:

正文{
背景色:#a3d5d3;
}

您需要为字母提供锚定标签,这些字母将链接到它需要指向的容器id

<h6 class="card-header crd-hr-custom border-bottom-0 text-center bg-primary text-light">
        1 2 3 4 5 6 7 8 9 <a href="#A">A</a> B C D E F G H I J K L M N O P Q R S T U V W Y X Z
      </h6>

1 2 3 4 5 6 7 8 9 B C D E F G H I J K L M N O P Q R S T U V W Y X Z
然后根据字母为每列分配id

    <!-- column -->
    <div class="row" id="A">
      <div class="col-lg-1">
        <span class="font30">A</span>
      </div>
      <div class="col-lg-11">
        <div class="container">
          <ul class="list-unstyled row">
            <li class="list-item col-md-3"> Test </li>
          </ul>
        </div>
      </div>
    </div>
    <!-- column -->

A.
    试验
希望这能回答您的问题。

像这样试试

$lastChar = '';
foreach ($dados['lojas'] as $row){
    $char2 = str_split($row->name); 
    $char = $char2[0];
    if ($char !== $lastChar) {
        if(empty($last_char)){
            $skill_data .= '<li><h3>'.strtoupper($char).'</h3></li>';
        }
        $lastChar = $char;
    }
    $skill_data .= '<li>'.$row->name.'</li>';
}
<li>A</li>
   <li>About Home</li>
   <li>Absolut Leather</li>
   <li>A Esportiva</li>
   ...
<li>B</li>
   <li>B2 Smile</li>
   <li>Balaroti</li>
   <li>Barceló Hotels & Resorts</li>
....
$lastChar='';
foreach($dados['lojas']作为$row){
$char2=str_split($row->name);
$char=$char2[0];
如果($char!=$lastChar){
if(空($last_char)){
$skill_data.='
  • '.strtoupper($char)。'
  • '; } $lastChar=$char; } $skill_data.='
  • '.$row->name.
  • '; }
    这个看起来像这样

    $lastChar = '';
    foreach ($dados['lojas'] as $row){
        $char2 = str_split($row->name); 
        $char = $char2[0];
        if ($char !== $lastChar) {
            if(empty($last_char)){
                $skill_data .= '<li><h3>'.strtoupper($char).'</h3></li>';
            }
            $lastChar = $char;
        }
        $skill_data .= '<li>'.$row->name.'</li>';
    }
    
    <li>A</li>
       <li>About Home</li>
       <li>Absolut Leather</li>
       <li>A Esportiva</li>
       ...
    <li>B</li>
       <li>B2 Smile</li>
       <li>Balaroti</li>
       <li>Barceló Hotels & Resorts</li>
    ....
    
  • A
  • 关于家
  • 绝对皮革
  • 埃斯波提娃
  • ...
  • B
  • B2微笑
  • 巴拉罗蒂
  • 巴塞罗酒店及度假村
  • ....
    假设
    $row->name
    是从对象数组中获取的类别名称


    注意:-CSS magic需要根据您的要求制作

    因为您这里没有足够的代码可以使用,而且这不是一个代码编写服务,我建议您搜索以下示例:“a-z分页codeigniter”,当您遇到更具体的问题而不是更广泛的问题时再回来“你能帮我完成90%的任务吗”问题。