[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 136
  • Last Modified:

Match comma Seperated value store in database

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,
0
software 100
Asked:
software 100
  • 3
1 Solution
 
Ahmed MerghaniSoftware EngineerCommented:
I did not see any function like this before "$this->explode()"! Did you write it or other wise change this line:
$subject_required=$this->explode(array(',',' '),$subject_required);

Open in new window

to
$subject_required=explode(',' ,$subject_required);

Open in new window

0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
You may want to use the mysql function FIND_IN_SET
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
You may want to use the mysql function FIND_IN_SET
0
 
software 100PHP Trainee DeveloperAuthor Commented:
thanks for answer ,will this function work with any data type.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
Short answer: well, yes, but...

The long answer is that the design is not really normalized and will usually give problems in the long run.
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now