Simple you can use WHERE clause to get resulr from database in Codeigniter. Follow this example.
$this->db->select(‘*’)->from(‘gallery’);
$this->db->where(‘column name’,$value);
$this->db->get();
If you want to get result using WHERE and LIKE in codeigniter then follow below example.
$this->db->select(‘*’)->from(‘gallery’);
$this->db->where(“column name LIKE ‘%$search_name%'”);
$this->db->get();
If you want to select records BETWEEN two dates then you need to follow this example code.
$this->db->select(‘*’)->from(‘Table Name’);
$this->db->where(“DATE_FORMAT(add_date,’%m’) BETWEEN ‘$start_month’ AND ‘$end_month’ “)
$this->db->get()->result();
The WHERE clause or MySQL WHERE condition is used to filter the results from a SELECT data, INSERT data, UPDATE data and DELETE data.
here you want to set where clause for get data from database in Codeigniter and data select from database with descending order.So first pass a unique value in the model page through Controller go to the model page where you write your query for select. The code is write below and I think it’s help for you
Controller:
public function get_table_data(){ $id=$this->input->post('u_id'); $this->MyModel->GetTabledata($id); }
Model:
public function GetTabledata($id){ $qry=$this->db->select('*')->from('Table Name')->where('id',$id)->order_by('id','desc')->get()->result(); return $qry; }