Solved

Match comma Seperated value store in database

Posted on 2014-12-05
5
110 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
OWA - local directory not showing 5 34
ADFS relying party - SP 3 52
IIS ISSUE while deploying the web application or web service 2 54
Unwanted Popup 8 29
New Relic: Our company recently started researching several products to figure out what were the best ways for us to increase our web page speed and to quickly identify performance problems that we may be having. One of the products we evaluated wa…
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…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

822 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