如何在Codeigniter中使用Ajax Datables中的or_where和where条件

codeigniter datatables

584 观看

2回复

20 作者的声誉

如何在OR条件下获取条件。并且在OR后使用的条件不起作用。

$this->datatables->select('otest_questions.qst_id,otest_sub_category.sub_cat_name,otest_subjects.subject_display_name,otest_questions.qst_question,otest_questions.qst_status');
        $this->datatables->join('otest_subjects',' otest_questions.qst_subject_id=otest_subjects.subject_id');
        $this->datatables->join('otest_main_category','otest_subjects.subject_main_cat_id=otest_main_category.main_cat_id');
        $this->datatables->join('otest_sub_category','otest_main_category.main_cat_id=otest_sub_category.sub_cat_main_cat_id');
        $this->datatables->where(array('otest_questions.qst_added_by'=>$this->session->userdata['inst_in']['inst_id'],'otest_questions.qst_chapter_id'=>$this->input->get('chapter')));
        $this->datatables->or_where(array('otest_questions.access_level'=>1));
        $this->datatables->where(array('otest_questions.qst_chapter_id'=>$this->input->get('chapter')));

        $this->datatables->group_by('otest_questions.qst_id');
        $this->datatables->from('otest_questions');
        }

        echo $this->datatables->generate(); 

执行的查询是

SELECT * FROM(otest_questions)JOIN otest_subjectsON otest_questionsqst_subject_id= otest_subjectssubject_idJOIN otest_main_categoryON otest_subjectssubject_main_cat_id= otest_main_categorymain_cat_idJOIN otest_sub_categoryON otest_main_categorymain_cat_id= otest_sub_categorysub_cat_main_cat_id 在哪里otest_questionsqst_added_by='12'AND otest_questionsqst_chapter_id='988'AND otest_questionsqst_chapter_id='988'OR otest_questionsaccess_level= 1 GROUP BY otest_questionsqst_id

但是查询应该是

在哪里otest_questionsqst_added_by='12'AND otest_questionsqst_chapter_id='988'OR otest_questionsaccess_level= 1 AND otest_questionsqst_chapter_id='988'

作者: Deepa 的来源 发布者: 2017 年 9 月 15 日

回应 2


0

1000 作者的声誉

决定
$inst_id = $this->session->userdata['inst_in']['inst_id'];
$chapter = $this->input->get('chapter');

$query = "SELECT * FROM (otest_questions)
JOIN otest_subjects ON otest_questions.qst_subject_id=otest_subjects.subject_id 
JOIN otest_main_category ON otest_subjects.subject_main_cat_id=otest_main_category.main_cat_id 
JOIN otest_sub_category ON otest_main_category.main_cat_id=otest_sub_category.sub_cat_main_cat_id 
WHERE (otest_questions.qst_added_by = '$inst_id' AND otest_questions.qst_chapter_id = '$chapter')
OR (otest_questions.qst_chapter_id = '$chapter' AND otest_questions.access_level = 1)
GROUP BY otest_questions.qst_id";

$this->datatables->query($query);
作者: Anil Shrestha 发布者: 2017 年 9 月 15 日

0

20 作者的声誉

 $query = "(SELECT a.qst_id,d.sub_cat_name,b.subject_display_name,a.qst_question,a.qst_status from otest_questions as a JOIN otest_subjects as b ON a.qst_subject_id = b.subject_id JOIN otest_main_category as c ON b.subject_main_cat_id = c.main_cat_id JOIN otest_sub_category as d ON c.main_cat_id = d.sub_cat_main_cat_id WHERE a.qst_added_by =".$this->session->userdata['inst_in']['inst_id'] ." AND a.qst_chapter_id =".$this->input->get('chapter')." OR a.access_level = 1 AND a.qst_chapter_id =".$this->input->get('chapter')." GROUP BY a.qst_id) as F";
    $this->datatables->select('*');
    $this->datatables->from($query);
    echo $this->datatables->generate(); 
作者: Deepa 发布者: 2017 年 9 月 15 日
32x32