【问题标题】:match Comma Separated value store in database php codeigniter匹配数据库php codeigniter中的逗号分隔值存储
【发布时间】:2014-12-06 06:33:00
【问题描述】:

我有项目要求,如果有任何科目与学院添加的科目相匹配,学生可以申请学位。 这是表结构

institute table                                 student table
----------------------------------            -----------------------------------
id | degree |       subject_required           id  |  subject_known
1  |   MS   |      maths,electronics,CAD        1    craft,drama 
2     BSC        chemistry,biology              2     maths
3     arts       craft,drama,dancing            3     cad,electronics

这是我写的代码,其中学院添加了学位和科目_required

public function add_degree($institute_id){
$data=array(
'id' => $institute_id,
'degree' => $this->input->post('degree'),
'subject_required'=>$this->input->post('subject_required'),
);
return $this->db->insert('institute',$data);
}

这段代码是学生第一次注册时写的

public function student_register(){
$data=array(
'id' => $institute_id,
'subject_known'=>$this->input->post('subject_known'),
);
return $this->db->insert('student',$data);
}

我如何匹配此科目要求,如果任何一门科目匹配,则学生可以申请,并且此科目按列分隔

public function match_subject($id){
$sql='SELECT subject_required   FROM institute  WHERE id ='.$id;
$query=$this->db->query($sql);
foreach ($query->result() as $row)
     {
     $subject_required = $row->subject_required;
         $subject_required=$this->explode(array(',',' '),$subject_required);

     }

}

但我无法满足主题要求。

【问题讨论】:

    标签: php mysql sql codeigniter


    【解决方案1】:

    尝试使用 MySQL 正则表达式

    select * from institute where subject_required REGEXP '[[:<:]]chemistry[[:>:]]'
    

    希望对你有帮助

    【讨论】:

    • 你的意思是我不需要使用爆炸功能?
    猜你喜欢
    • 2014-04-17
    • 1970-01-01
    • 2013-06-07
    • 2018-04-11
    • 1970-01-01
    • 2011-05-30
    • 1970-01-01
    • 1970-01-01
    • 2010-10-18
    相关资源
    最近更新 更多