Mysql
 sql >> Teknologi Basis Data >  >> RDS >> Mysql

Codeigniter pilih- dari- mana

Coba ini, ini akan berhasil, saya memberi Anda dua opsi untuk di mana jadi gunakan yang Anda butuhkan

 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. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Perbandingan MySQL dengan nilai nol

  2. Tidak dapat menambahkan batasan kunci asing MySql

  3. SQL bergabung dengan bantuan untuk daftar teman

  4. Bagaimana cara kerja NOT IN subquery dengan nilai NULL?

  5. MySQL Query - Jumlahkan Kapasitas Beberapa Gudang