CodeIgniter Select Statement with Where clause

后端 未结 4 479
自闭症患者
自闭症患者 2021-01-28 17:55

Hi I\'m new to CodeIgniter and I just want to know How will I query from my MySql Db, a Select Statement with a where clause, I know it can be searched from the net but whenever

相关标签:
4条回答
  • 2021-01-28 18:10

    You can do as Mehedi-PSTU stated, however it seems as though you're a little new to this, so here's some extra information:

    I'll copy Mehedi-PSTU for the most part here.

    $this->get->where('column_name', $equals_this_variable);
    $query = $this->db->get('table_name');
    

    This will store the query object in the variable $query. if you wanted to convert that to a usable array, you just perform to following.

    $results = $query->result_array();
    

    Or you can loop through it like this:

    foreach($query->result_array() as $result){
        // Perform some task here.
    }
    

    A better or even full understanding can probably come from:

    http://ellislab.com/codeigniter/user-guide/database/active_record.html

    0 讨论(0)
  • 2021-01-28 18:20

    In Codeigniter with Method Chaining Style :-

     $data['getData'] = $this->db->get_where('table_name',array('column_name'=>$var))->result_array();
    
    0 讨论(0)
  • 2021-01-28 18:21

    Try this one.

    $id = 'your id';
    $this->db->select("*");
    $this->db->from("table_name");
    $this->db->where('id','$id');
    $query = $this->db->get();
    return $query->result_array();
    
    0 讨论(0)
  • 2021-01-28 18:32

    Try something like this

        $this->db->where('db_attr', $var);
        return $this->db->get('table');
    
    0 讨论(0)
提交回复
热议问题