codeigniter Query Structure Selecting Data


Example

Selecting data with condition

$query  = $this->db->select('*')
                   ->from('table_name')
                   ->where('column_name', $value) // Condition 
                   ->get();
return $query->result();

Selecting data with multiple conditions

$conditions = array('column_name_1' => $value_1, 'column_name_2' => $value_2);
$query  = $this->db->select('*')
                   ->from('table_name')
                   ->where($conditions) // Conditions
                   ->get();
return $query->result();

Select data with condition and limit

$query  = $this->db->select('*')
                   ->from('table_name')
                   ->where('column_name', $value) // Condition
                   ->limit(10) // Maximum 10 rows
                   ->get();
return $query->result();

Select data with condition, maximum rows and order descending

$query  = $this->db->select('*')
                   ->from('table_name')
                   ->where('column_name', $value) // Condition
                   ->limit(10) // Maximum 10 rows 
                   ->order_by('id','DESC') // Order data descending 
                   ->get();
return $query->result();