Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php codeigniter中1个表中具有相同标题的单独行_Php_Html_Codeigniter_Codeigniter 2 - Fatal编程技术网

Php codeigniter中1个表中具有相同标题的单独行

Php codeigniter中1个表中具有相同标题的单独行,php,html,codeigniter,codeigniter-2,Php,Html,Codeigniter,Codeigniter 2,我想分离我的同名“标题”,并使用codeigniter将它们分组到单独的表中。下面是我在codeigniter中的表格、期望输出和MVC: my table: evaluation | id | instructor| title | result | | 1 | Mark | Module1 | 5 | | 2 | Dave | Module1 | 10 | |

我想分离我的同名“标题”,并使用codeigniter将它们分组到单独的表中。下面是我在codeigniter中的表格、期望输出和MVC:

my table: evaluation
|   id  |   instructor|   title       |   result  |
|   1   |   Mark      |   Module1     |   5       |
|   2   |   Dave      |   Module1     |   10      |
|   3   |   Noel      |   Module2     |   6       |
|   3   |   Mike      |   Module3     |   11      |

Desired output:
in table (Module1)
|   instructor|   result  |
|   Mark      |   5       |
|   Dave      |   10      |

in table (Module2)
|   instructor|   result  |
|   Noel      |   6       |

in table (Module3)
|   instructor|   result  |
|   Mike      |   11      |
我的模型

public function view_evaluation(){      

    $this->db->select('*');
    $this->db->order_by('title');
    $this->db->from('evaluation');
     $query = $this->db->get()->result_array();
        return $query;

}
我的控制器

public function admin_view_evaluation()
{ 
   $view_evaluation = $this->admin_model->view_evaluation();
   $data = array('view_evaluation' => $view_evaluation);
   $this->load->view('admin/admin_view_evaluation_page', $data);
}
我的看法

<?php foreach($view_evaluation as $view){  ?>
 <table id="source" class="table table-bordered table-hover">
   <caption style="color: #fff;">
     <?php echo $view['title']; ?>
   </caption>
  <thead>
    <tr>
      <th>Instructor</th>
      <th>Results</th>
    </tr>
  </thead>
  <tbody>

   <?php foreach($view_evaluation as $get){  ?>
      <tr>
            <th><?php echo $get['instructor']; ?></th>
            <td><?php echo $get['result']; ?></td>
      </tr>
   <?php }  ?>
  </tbody>
</table>

教练
结果

我的学校项目请帮助我..提前非常感谢..

试试这个例子这会很好

public function results (){

    $query   = $this->db->group_by('title');
    $query   = $this->db->get('evaluation');
    $results = $query->result();

    foreach ($results as $res) {
        echo $res->title."<br/>";
        $rrr = $this->singleres($res->title);
        foreach($rrr as $r){
            echo "Name  :".$r->instructor;
            echo "Score :".$r->result."<br/>";
        }
    }
}

public function singleres($title){
    $this->db->where('title', $title);
    $query = $this->db->get('evaluation');
    return $query->result();
}
公共功能结果(){
$query=$this->db->group_by('title');
$query=$this->db->get('evaluation');
$results=$query->result();
foreach(结果为$res){
echo$res->title.“
”; $rrr=$this->singleres($res->title); 外汇储备($rrr为$r){ echo“名称:”.$r->讲师; 回显“分数:”.r->结果“
”; } } } 公共功能单体($title){ $this->db->where('title',$title); $query=$this->db->get('evaluation'); 返回$query->result(); }
发送要查看的值

public function results (){
    $this->load->model('Test_model');
    $this->load->view('testview');
}
然后测试模型

Class Test_model extends CI_Model{
public function onlytitlrresults(){
    $query   = $this->db->group_by('title');
    $query   = $this->db->get('evaluation');
    $results = $query->result();
    return $results;
}
public function singleres($title){
    $this->db->where('title', $title);
    $query = $this->db->get('evaluation');
    return $query->result();
}}
然后创建视图文件

<ul>
<?php $results = $this->Test_model->onlytitlrresults();
$rrr = $this->Test_model->singleres($res->title);?>
<li>
<?php echo $res->title."<br/>"; ?>
</li>
<ul>
    <?php foreach($rrr as $r){?>
    <li><?php echo "Name  :".$r->instructor;?></li>
    </li><?php echo "Score :".$r->result;?></li>
    <?php }?>
</ul>
<?php }?>
</ul> 

欢迎来到堆栈溢出。你已经尝试过什么来解决这个问题了?要求家庭作业帮助的问题必须包括到目前为止你为解决问题所做工作的总结,以及对你解决问题的困难的描述。请检查。是@MarkJosephPino检查下面的示例@MarkJosephPino