CodeIgniter Forums
SQL query - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: SQL query (/showthread.php?tid=70760)



SQL query - ben beker - 05-26-2018

Hi, how to create a selection query that retrieves information between two given dates. 


thanks for your replies  Rolleyes


RE: SQL query - hipm - 05-26-2018

Look here please.
https://stackoverflow.com/questions/4875668/codeigniter-getting-data-posted-in-between-two-dates/4876589


RE: SQL query - ben beker - 05-28-2018

Hi hipm, the examples provide by https://stackoverflow.com/questions/4875...es/4876589 doesn't work for me. please look my controller and my model codes and explain me why it doesn't work. thanks for your answers.

This is my mode

public function getRecordsKpicon( $data ){
$this->db->select('station_nom, kpi_cate, kpi_nom, kpi_valeur, kpi_date, kpi_heure');
$this->db->from('kpi');
$this->db->join('station_base', 'station_base.station_id = kpi.station_id');
$this->db->where( $data );
$query = $this->db->get();
return $query->result();
}

and this is my controller

ublic function viewconsukpi(){

$data = array('type_reseau' => $this->input->post('type_reseau'), 'kpi_type'=> $this->input->post('kpi_type'), 'kpi_nom'=> $this->input->post('kpi_nom'), 'region'=> $this->input->post('region'), 'ville'=> $this->input->post('ville'), 'centre'=> $this->input->post('centre'), 'site'=> $this->input->post('site'), 'kpi_date <='=> $this->input->post('datedebut'), 'kpi_date >='=> $this->input->post('datefin')
);
$this->load->model('Kpimodel');
$records = $this->Kpimodel->getRecordsKpicon( $data );
$this->load->view('kpilist', ['records'=>$records]);


}


RE: SQL query - ben beker - 05-29-2018

HI,

I want to select station_nom, kpi_cate, kpi_nom, kpi_valeur, kpi_date, kpi_heure into the table kpi between two dates. I show you my controller and my model that I wrote. Unfortunately, my request generates the error below:

Error Number: 1064

Erreur de syntaxe près de '`NULL` AND `kpi_date` > `IS` `NULL`' à la ligne 10

SELECT `station_nom`, `kpi_cate`, `kpi_nom`, `kpi_valeur`, `kpi_date`, `kpi_heure` FROM `kpi` JOIN `station_base` ON `station_base`.`station_id` = `kpi`.`station_id` WHERE `type_reseau` IS NULL AND `kpi_type` IS NULL AND `region` IS NULL AND `ville` IS NULL AND `centre` IS NULL AND `site` IS NULL AND `kpi_date` < `IS` `NULL` AND `kpi_date` > `IS` `NULL`

Filename: C:/wamp/www/CodeIgniter/system/database/DB_driver.php

Line Number: 691