Solved

Match comma Seperated value store in database

Posted on 2014-12-05
5
109 Views
Last Modified: 2014-12-06
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
Comment
Question by:software 100
  • 3
5 Comments
 
LVL 8

Expert Comment

by:Ahmed Merghani
ID: 40484334
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
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 40484352
You may want to use the mysql function FIND_IN_SET
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 40484353
You may want to use the mysql function FIND_IN_SET
0
 

Author Closing Comment

by:software 100
ID: 40484360
thanks for answer ,will this function work with any data type.
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 40484370
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

      Install BugTracker on Windows 2008 server Step 1:  Install windows 2008 server 32 bit OS and configure IIS. Step 2:  Install SQL server ( SQL server 2005 or SQL server 2005 Express edition. The installer for 2008  version isn’t very f…
Developer tools in browsers have been around for a while, yet they are still heavily underused by developers. Developers still fix html or CSS then refresh page to see effect, or they put alert or debugger in JavaScript and then try again and again …
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now