Hello Masters,

I need help.I can't apply WHERE Condition clause in my Multiple selected checkbox value.like If i select 'accounitng' or 'php' then i want here use a condition like WHERE ("skill", "php") here, skill table field name and php checkbox selected value.If i select a category 'PHP' so all 'PHP' related data only show.Checkbox selected value save into databse with ' , ' comma separated. like php,java,accounting,sql

For save data i used for Model:

public function saveInstituteOfferCourse($data = array()) {
        if ($this->db->insert('tbl_course_offred', $data)) {
            return $this->db->insert_id();
        }
        return FALSE;
    }

for controller i use:

public function saveCourses() {
        $data = array();
        $this->load->library('form_validation');
        $this->form_validation->set_rules('skill', 'skill', 'required');
        if ($this->form_validation->run()) {
            /* @var $skill user_admin_controller */
            $skill = implode(',', $this->input->post('skill'));
            $data['skill'] = $skill;
            $data['user_id'] = $this->session->userdata('user_id');
            $this->user_admin_model->saveInstituteOfferCourse($data);
            redirect("user_admin_controller/userAdminPanel");
        }
    }

My workflow likes:

First: user select many skills using multiple checkbox and save selected data into DB table.

Second: if anyone click on category on fronted page like php or java then only php or java related data information/list show.

How can i do this please help me or suggest me for best.if possible provide me source code in codeignitor.

My applying code have a look,

Model,

public function selectaccoutingins() {
        $this->db->select('*');
        $this->db->select('skill');
        $this->db->from('tbl_user_reg, tbl_course_offred');
        $this->db->where('skill', "php");
        // here, i use two table 1 for information collect and other for category match condition value show.

        $query_result = $this->db->get();
        $result = $query_result->result();
        $result = explode(",", $query_result->result);
        return $result;

    }

Controller,

function accounting_ins_list() {
        $data = array();
        $data['result'] = $this->welcome_model->selectaccoutingins();
        $data['catepage_list'] = $this->load->view('accounting_ins_list', $data, true);
        $this->load->view('hmcate_select_page', $data);
    }

view,

               <tbody>
                    <?php

                    if($result) {
                    foreach ($result as $aresult) {
                    ?>
                    <tr>
                        <td><?php echo $aresult->institute_name;?></td>
                        <td><?php echo $aresult->contact_person; ?></td>
                        <td><?php echo $aresult->institute_address1;?></td>
                    </tr>
                    <?php } 

                    }   ?>
                </tbody>

here i want to show only PHP related information list.Please help how can i solve this.

Best regards,

Can you post the results of:

show create table tbl_user_reg\G
show create table tbl_course_offred\G

It will help to understand the relations between the two tables.
If I understood your request in tbl_course_offred you have a column skills which is varchar and saves multiple values as php,css,html and you want to be able to search one of those?

If yes, you can use a fulltext search query: http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html

In order to work you have to add a fulltext index to the table, which needs to be MyISAM (it works with InnoDB only from MySQL 5.6 and above). But there are some limits:

1) words less or equal to 3 characters are not considered, unless you edit/add ft_min_word_len in the config file of the MySQL server (/etc/mysql/my.cnf), otherwise if you want to search php you get an empty result set. After the edit you have to reload/restart MySQL server and rebuild the fulltext index by running repeair table table_name;
2) if the searched word represents more then 50% of the index the query will return an empty set;
3) you need more then 3 rows to get results;
4) it doesn't work across multiple tables, but you can perform a subquery to provide a value to search in the other table.

An usage example: http://dev.mysql.com/doc/refman/5.0/en//fulltext-natural-language.html

In CodeIgniter, as the previous thread of yours, you have to use the query method, an example:

$this->db->query("SELECT * FROM tbl_course_offred MATCH(skills) AGAINST('php')");
Member Avatar for diafol

I won't go into your code, but if you want a WHERE clause from checkboxes:

Say your form is like this

<input type="checkbox" name="where[]" value="php" />
<input type="checkbox" name="where[]" value="java" />

You can pick it up like this and create a where clause:

if(isset($_POST['where'])){
    $whereArray = (array) $_POST['where'];
    $where = " WHERE myfield IN ('" . implode("','", $whereArray) . "')"; 
}else{
    $where = '';
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.