// Step 1: Load the Query Builder module in your controller or model
$this->load->database();
// Step 2: Specify the table you want to select data from
$this->db->table('your_table_name');
// Step 3: Define the columns you want to retrieve, use '*' for all columns
$this->db->select('column1, column2');
// Step 4: Add conditions using where() method (optional)
$this->db->where('column_name', $value);
// Step 5: Add additional conditions or join clauses if needed (optional)
$this->db->join('another_table', 'another_table.id = your_table_name.related_id');
// Step 6: Specify ordering if needed (optional)
$this->db->orderBy('column_name', 'ASC');
// Step 7: Set limit and offset for pagination (optional)
$this->db->limit($limit, $offset);
// Step 8: Execute the query and get the result
$result = $this->db->get();
// Step 9: Check if the query was successful
if ($result) {
// Step 10: Fetch the result as an array
$data = $result->getResultArray();
} else {
// Handle the query failure
$data = array();
}
// Step 11: Return or use the retrieved data
return $data;