Mysql
 sql >> Datenbank >  >> RDS >> Mysql

Kozünder auswählen- woher

Versuchen Sie dies, es sollte funktionieren, ich habe Ihnen zwei Optionen gegeben, wo Sie also diejenige verwenden können, die Sie benötigen

 public function did_filter() {

    $types = $this->input->post('types');

    //list of types column name you can ignore this part by in cases someone change the value in html your query will fail so i am keeping this
    $data = array(
        '2g' => 0,
        '3g' => 0,
        '4g' => 0,
    );

    $this->db->select('*');
    $this->db->from('table_example');
    $this->db->where('phone', $this->input->post('phone'));

    // if you want to use and where use this block, or use the next block the is commented out
    foreach ($types as $type) {
        if (isset($data[$type])) { // this making sure that your column is correct 
            $this->db->where($type, 1);
        }
    }

    /**
    //If you want your checkbox to work as or, ie if 2g and 3g select and you want to show any check box match. 
    //In case of your example still it will give row 1 and 4, but if you use fist block it will give you row 1 only because row 1 got both 2g and 3g
    $or_where = array();
    foreach ($types as $type) {
        if (isset($data[$type])) { // this makeing sure that your colum is correct 
            $or_where[] = "$type = 1";
        }
    }
    if (count($or_where) > 0) {
        $where = implode(' OR ', $or_where); // make the or where for array
        $this->db->where("($where)");
    }
     * 
     */

    $query = $this->db->get();

    if ($query && $query->num_rows() > 0) {
        return $query->result_array();
    } else {
        return false;
    }
}