如何在codeigniter中计算表中的行数并在其中显示其他详细信息?

时间:2014-04-15 07:37:59

标签: php mysql codeigniter

大家好我有问题请帮帮我

我有两个表格主题,其他是问题

主题表中的

字段是

+------+-----------+-----------+
| id   | name      | set_id    |   
+------+-----------+-----------+
问题表中的

+------+-----------+-----------+-----------+---------------+
| id   |question         | answer         | subject        |
+------+-----------+-----------+-----------+---------------+

我想显示如下图片的详细信息 enter image description here

如何做到这一点,请帮助我,你的帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

function subjectlist(){
  $val=array('a.id','a.name','a.set_id','b.set_name');
  $where=array('user_id'=>$this->session->userdata['logged_in']['id']);
  $sub=$this->login->get_join($val,'','b.id=a.set_id',$where,'subject as a','q_set as b');
  $count_all=array();

  foreach($sub as $count) {
    $where1=array('subject_id'=>$count->id);
    $count_all[]=array('id'=>$count->id,'name'=>$count->name,'set_id'=>$count->set_id,'set_name'=>$count->set_name,'all_val'=>$this->login->count_val($where1,'question'));
  }
  $data['subject']=$count_all;
  $this->load->view('i_user/subject_list',$data);
}