sql >> データベース >  >> RDS >> Mysql

Codeigniter select-from- where

    これを試してみてください。うまくいくはずです。必要なものを使用するための2つのオプションを提供しました

     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;
        }
    }
    


    1. 巨大なデータを含むテーブルのクエリ実行時間を短縮する方法

    2. 多対多の関係

    3. オブジェクトタイプのテーブルへの選択を実行することは可能ですか?

    4. PDObindParamの問題