Welcome Guest, Not a member yet? Register   Sign In
SQL query
#1

Hi, I have a problem. I want to select the average of kpi'values but it doesn't work. this my controllers:

<?php
class Analysekpi extends CI_Controller{

public function index(){

$this->load->view('analysekpi');
}


public function viewanalkpi(){
/*$this->form_validation->set_rules('type_reseau', 'type');
$this->form_validation->set_rules('kpi_type', 'type kpi');
$this->form_validation->set_rules('kpi_nom', 'nom kpi');
$this->form_validation->set_rules('region', 'region');
$this->form_validation->set_rules('ville', 'ville');
$this->form_validation->set_rules('centre', 'centre');
$this->form_validation->set_rules('site', 'site');
$this->form_validation->set_rules('datedebut', 'date debut', 'required', array('required' => 'le champ %s doit être renseigné.'));
$this->form_validation->set_rules('datefin', 'date fin', 'required', array('required' => 'le champ %s doit être renseigné.'));
$this->form_validation->set_error_delimiters('<div class="text-danger">', '</div>');*/

$data1 = array('nomtype'=> $this->input->post('type_reseau'), 'nomdonnee'=> $this->input->post('kpi_type'));
/*$data2 = array('kpinom' => $kpinom, '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')
            );*/

$data2 = array('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->getRecordsnomkpi( $data1 );
for ($i=0; $i < sizeof($records); $i++) { 

/*$kpinom = $records[$i];

$avg = $this->Kpimodel->getRecordsavgvalue( $data2);

var_dump($avg);
var_dump($records[$i]);*/



}


$this->load->view('kpilistanal', ['records'=>$records]); 



}

}

?>


and this is my models


<?php
class Kpimodel extends CI_Model{

/*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();
}*/


public function getRecordsKpicon( $data ){
$this->db->select('station_nom, categorie, 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->join('nomkpi', 'nomkpi.idnomkpi = kpi.idnomkpi');
$this->db->where( $data );
$query = $this->db->get();
return $query->result();
}


function getParent($data){
$this->db->select('kpinom');
$this->db->from('nomkpi');
$this->db->join('typereseau', 'typereseau.idtype = nomkpi.idtype', 'left');
$this->db->join('typedonnee', 'typedonnee.iddonnee = nomkpi.iddonnee', 'left');
$this->db->where( $data );
$query = $this->db->get();
return $query->result_array();

}

public function getRecordsKpiprev( $data ){
$this->db->select('station_nom, categorie, 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->join('nomkpi', 'nomkpi.idnomkpi = kpi.idnomkpi');
$this->db->where( $data );
$query = $this->db->get();
return $query->result();
}


public function getRecordsKpianal( $data ){
$this->db->select('station_nom, categorie, 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->join('nomkpi', 'nomkpi.idnomkpi = kpi.idnomkpi');
$this->db->where( $data );
$query = $this->db->get();
return $query->result();
}


public function getRecordsnomkpi( $data ){
/*$this->db->select('idnomkpi, kpinom, categorie, seuil, cause');*/
$this->db->select('kpinom');
$this->db->from('nomkpi');
$this->db->join('typedonnee', 'typedonnee.iddonnee = nomkpi.iddonnee');
$this->db->join('typereseau', 'typereseau.idtype = nomkpi.idtype');
$this->db->where( $data );
$query = $this->db->get();
return $query->result();
}

public function getRecordsavgvalue( $data){
$this->db->select_avg('kpi_valeur');
$this->db->from('kpi');
$this->db->join('station_base', 'station_base.station_id = kpi.station_id');
$this->db->join('nomkpi', 'nomkpi.idnomkpi = kpi.idnomkpi');
/*$this->db->where( $kpinom);*/
$this->db->where( $data );
$query = $this->db->get();
return $query->result();
}

public function saveRecordanalkpi( $data ){
return $this->db->insert('analysekpi', $data);
}


public function getRecordsanalkpi( $data ){
$this->db->select('anal_id, kpinom, categorie, seuil, avgvalue, cause');
$this->db->from('analysekpi');
$this->db->join('nomkpi', 'nomkpi.idnomkpi = analysekpi.idnomkpi');
$this->db->where( $data );
/*$this->db->group_by('categorie');*/
$query = $this->db->get();
return $query->result();
}

public function saveRecordlog( $data ){
return $this->db->insert('logs', $data);
}


public function getRecordslog( $data ){
$this->db->select('log_id, user_nom, kpinom, categorie, seuil, avgvalue, erreur, actions_entreprises');
$this->db->from('logs');
$this->db->join('user', 'user.user_id = logs.user_id');
$this->db->join('nomkpi', 'nomkpi.idnomkpi = logs.idnomkpi');
$this->db->join('analysekpi', 'analysekpi.anal_id = logs.anal_id');
$this->db->where( $data );
/*$this->db->group_by('categorie');*/
$query = $this->db->get();
return $query->result();
}



}

?>



please help me
Reply
#2

Pages of code and then "it doesn't work"???

1) Use the bbcode tags (https://forum.codeigniter.com/misc.php?a...help&hid=7) to make your posts more readable. No one wants to scroll through pages of code to read a forum section.
2) If there is a problem, state or show it. What were you expecting? What happened?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB