Issue
Currently I'm trying to retrieve all the entries from my data that are within a particular timeframe. To do this I have a method in my model class with the following statement:
public function get_records_all($st_date,$end_date){
$sql = SELECT
*
FROM `crm_listings`
WHERE added_date BETWEEN '" . $st_date . "' AND '".$end_date."'
ORDER BY `added_date` DESC;
$response = $this->db->query($sql);
echo $response;
}
And in my controller class I'm using the following statement to show the output:
function fetch_status(){
$startDate = '';
$endDate = '';
$this->load->model('crm/user_model');
if($this->input->post('startDate')){
$startDate = $this->input->post('startDate');
}
if($this->input->post('endDate')){
$endDate = $this->input->post('endDate');
}
$data_all = $this->user_model->get_records_all($startDate,$endDate);
}
But this gives me the following error:
Solution
Try this
CodeIgniter gives you access to a Query Builder class. This pattern allows information to be retrieved, inserted, and updated in your database with minimal scripting. In some cases, only one or two lines of code are necessary to perform a database action. CodeIgniter does not require that each database table be its own class file. It instead provides a more simplified interface.
public function get_records_all($st_date,$end_date){
$this->db->where('added_date >=', $st_date);
$this->db->where('added_date <=', $end_date);
$this->db->order_by('added_date', 'DESC');
return $this->get('crm_listings')->result();
}
For more use this link CI Query Builder CLass
Answered By - Danish Ali
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.