• <legend id='AJTpZ'><style id='AJTpZ'><dir id='AJTpZ'><q id='AJTpZ'></q></dir></style></legend>
      <bdo id='AJTpZ'></bdo><ul id='AJTpZ'></ul>

        <tfoot id='AJTpZ'></tfoot>

        <small id='AJTpZ'></small><noframes id='AJTpZ'>

        <i id='AJTpZ'><tr id='AJTpZ'><dt id='AJTpZ'><q id='AJTpZ'><span id='AJTpZ'><b id='AJTpZ'><form id='AJTpZ'><ins id='AJTpZ'></ins><ul id='AJTpZ'></ul><sub id='AJTpZ'></sub></form><legend id='AJTpZ'></legend><bdo id='AJTpZ'><pre id='AJTpZ'><center id='AJTpZ'></center></pre></bdo></b><th id='AJTpZ'></th></span></q></dt></tr></i><div id='AJTpZ'><tfoot id='AJTpZ'></tfoot><dl id='AJTpZ'><fieldset id='AJTpZ'></fieldset></dl></div>
      1. 使用 Code Igniter 控制器和视图创建 foreach 循环

        Creating foreach loops using Code Igniter controller and view(使用 Code Igniter 控制器和视图创建 foreach 循环)
          <legend id='Td7OA'><style id='Td7OA'><dir id='Td7OA'><q id='Td7OA'></q></dir></style></legend>

              <bdo id='Td7OA'></bdo><ul id='Td7OA'></ul>
            • <small id='Td7OA'></small><noframes id='Td7OA'>

              1. <i id='Td7OA'><tr id='Td7OA'><dt id='Td7OA'><q id='Td7OA'><span id='Td7OA'><b id='Td7OA'><form id='Td7OA'><ins id='Td7OA'></ins><ul id='Td7OA'></ul><sub id='Td7OA'></sub></form><legend id='Td7OA'></legend><bdo id='Td7OA'><pre id='Td7OA'><center id='Td7OA'></center></pre></bdo></b><th id='Td7OA'></th></span></q></dt></tr></i><div id='Td7OA'><tfoot id='Td7OA'></tfoot><dl id='Td7OA'><fieldset id='Td7OA'></fieldset></dl></div>
                  <tbody id='Td7OA'></tbody>

                  <tfoot id='Td7OA'></tfoot>
                  本文介绍了使用 Code Igniter 控制器和视图创建 foreach 循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  这是我遇到过几次的情况,我只想一劳永逸地解决它.

                  This is a situation I have found myself in a few times and I just want clear it up once and for all.

                  最好只是在一些示例代码中向您展示我需要做什么.

                  Best just to show you what I need to do in some example code.

                  我的控制器

                  function my_controller()
                  {
                  
                  $id = $this->uri->segment(3);
                  
                  $this->db->from('cue_sheets');
                  $this->db->where('id', $id);
                  $data['get_cue_sheets'] = $this->db->get();
                  
                  $this->db->from('clips');
                  $this->db->where('sheet_id', ' CUE SHEET ID GOES IN HERE ??? ');
                  $data['get_clips'] = $this->db->get();
                  
                  $this->load->view('show_sheets_and_clips', $data);
                  
                  }
                  

                  我的观点

                  <?php if($get_cue_sheets->result_array()) { ?>
                      <?php foreach($get_cue_sheets->result_array() as $sheetRow): ?>
                          <h1><?php echo $sheetRow['sheet_name']; ?></h1>
                          <br/>
                          <?php if($get_clips->result_array()) { ?>
                              <ul>
                                  <?php foreach($get_clips->result_array() as $clipRow): ?>
                                      <li><?php echo $clipRow['clip_name']; ?></li>
                                  <?php endforeach; ?>
                              </ul>
                          <?php } else { echo 'No Clips Found'; } ?>
                      <?php endforeach; ?>
                  <?php } ?>
                  

                  所以基本上我试图显示一些工作表,然后在每个工作表中显示属于该工作表的剪辑.

                  So basically I am trying to display a number of sheets and then within each of those sheets the clips that belong to that sheet.

                  我希望这对外面的人有意义.

                  I hope this makes sense to someone out there.

                  谢谢,

                  蒂姆

                  推荐答案

                  Code Igniter 论坛上的一位用户提出了以下解决方案.原始线程是这里.

                  A user on the Code Igniter Forums came up with the solution below. The original thread is here.

                  单独查找每张纸的剪辑效率不高.使用 JOIN 查询同时获取两个列表.

                  It’s not efficient to look up the clips for every sheet separately. Use a JOIN query to get both lists at the same time.

                  // get the data
                  $this->db->from('cue_sheets');
                  $this->db->where('cue_sheets.id', $id);
                  $this->db->join('clips', 'clips.sheet_id = cue_sheets.id', 'left');
                  $rawdata = $this->db->get()->result_array();
                  // prepare the data into a multidimensional array
                  $data = array();
                  foreach($rawdata as $row)
                  {
                    // if this is the first clip of a new sheet, make a new entry for it
                    if (!isset($data[$row['id']]))
                    {
                      $data[$row['id']] = $row;
                      $data[$row['id']]['clips'] = array();
                    }  
                  
                    // add the current clip to the sheet
                    $data[$row['id']]['clips'][] = $row;
                  }
                  

                  现在在您的视图中,您可以循环浏览工作表,并在其中循环浏览剪辑:

                  Now in your view you can loop through the sheets, and within that, loop through the clips:

                  foreach($data as $sheet) {
                    // make header etc.
                    if (sizeof($sheet['clips']))
                    {
                      foreach($sheet['clips'] as $clip)
                      {
                        // show clip
                      }
                    } else {
                      // show 'no clips'
                    }
                  } 
                  

                  再次感谢,

                  蒂姆

                  这篇关于使用 Code Igniter 控制器和视图创建 foreach 循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                        <tbody id='QiLPr'></tbody>
                    • <i id='QiLPr'><tr id='QiLPr'><dt id='QiLPr'><q id='QiLPr'><span id='QiLPr'><b id='QiLPr'><form id='QiLPr'><ins id='QiLPr'></ins><ul id='QiLPr'></ul><sub id='QiLPr'></sub></form><legend id='QiLPr'></legend><bdo id='QiLPr'><pre id='QiLPr'><center id='QiLPr'></center></pre></bdo></b><th id='QiLPr'></th></span></q></dt></tr></i><div id='QiLPr'><tfoot id='QiLPr'></tfoot><dl id='QiLPr'><fieldset id='QiLPr'></fieldset></dl></div>

                      <tfoot id='QiLPr'></tfoot>

                      <legend id='QiLPr'><style id='QiLPr'><dir id='QiLPr'><q id='QiLPr'></q></dir></style></legend>
                        <bdo id='QiLPr'></bdo><ul id='QiLPr'></ul>

                            <small id='QiLPr'></small><noframes id='QiLPr'>