Solved

Match comma Seperated value store in database

Posted on 2014-12-05
5
108 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
Comment Utility
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]
Comment Utility
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
Comment Utility
You may want to use the mysql function FIND_IN_SET
0
 

Author Closing Comment

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

Expert Comment

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Thoughout my experience working on eCommerce web applications I have seen applications succumbing to increased user demand and throughput. With increased loads the response times started to spike, which leads to user frustration and lost sales. I ha…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
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…
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

772 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

11 Experts available now in Live!

Get 1:1 Help Now