Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Match comma Seperated value store in database

Posted on 2014-12-05
5
Medium Priority
?
125 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 143

Expert Comment

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

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1500 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 143

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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

730 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