match逗号分隔值存储在数据库php codeigniter中 [英] match Comma Separated value store in database php codeigniter
本文介绍了match逗号分隔值存储在数据库php codeigniter中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有项目要求,学生可以申请学位,如果有任何主题与学院添加的主题匹配。
这里是表结构
研究所学生表
--------- ------------------------- ------------------------- ----------
id |度| subject_required id | subject_known
1 | MS |数学,电子,CAD 1工艺,戏剧
2 BSC化学,生物学2数学
3艺术工艺,戏剧,舞蹈3 cad,电子学
这是代码我写了学院增加学位和subject_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);
}
}
b p $ p>
select * from institute where subject_required REGEXP'[[:<:]] chemistry [[:>:]]'
我希望这会帮助你
i have the project requirement where student can apply to the degree if there any subject matches with subject added by institute. here is the table structure
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
this is code i have written where institute added degree and subject_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);
}
and this code written when student 1st register himself
public function student_register(){
$data=array(
'id' => $institute_id,
'subject_known'=>$this->input->post('subject_known'),
);
return $this->db->insert('student',$data);
}
how do i match this subject requirement where if any one subject matches then student can apply and this subjects are separed by column
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);
}
}
but i m not able to match the subject requirement.
解决方案
try with MySQL Regex
select * from institute where subject_required REGEXP '[[:<:]]chemistry[[:>:]]'
i hope this will help you
这篇关于match逗号分隔值存储在数据库php codeigniter中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文