我有两个表subject_list和问题 subjectId是问题表中的外键。
我正在使用xcrud显示主题表,以及 我想计算来自问题表的特定主题的问题数量。
$this->load->library('loadxcrud');
echo Xcrud::load_css();
$xcrud = Xcrud::get_instance();
$xcrud->table('subject_list');
$xcrud->columns("subject_name,description,id");
$xcrud->fields("subject_name,description");
$xcrud->label("id", "No. of questions");
//$xcrud->join('id','question_details','subject_id');
$xcrud->before_insert('checksubjectexist');
$xcrud->before_update('checksubjectexistupdate');
$xcrud->pass_var("entry_by", 1);
$xcrud->validation_required('subject_name,description');
$xcrud->limit(5);
$xcrud->unset_edit(FALSE);
$xcrud->unset_add(FALSE);
$xcrud->unset_view(FALSE);
$xcrud->unset_print(FALSE);
$xcrud->unset_csv(TRUE);
$xcrud->unset_search(FALSE);
$xcrud->unset_title(TRUE);
$xcrud->unset_remove(TRUE);
echo $xcrud->render();
如果可以,请帮助我
答案 0 :(得分:1)
您可以使用subselect。
$xcrud->subselect( 'Questions', 'SELECT COUNT( * ) FROM questions q WHERE q.subjectId = {id}' );
$xcrud->columns("subject_name,description,id,Questions");