What is the difference between this two way and Which one is best? What do you suggest?
1.
Use of query (db) directly in CI_Controller. as:
$id = $this->input->post('id');
$query = $this->db->get_where('table1', array('id' => $id))->row();
$this->db->get_where('table2', array('idre' => $query->idre));
Or
2.
Use of query (db) in CI_Model and call it in CI_Controller. as:
CI_Model:
function GetWhere($table,$where){
return $this->db->get_where($table, $where);
}
CI_Controller:
$id = $this->input->post('id');
$query = $this->model_name->GetWhere('table1', array('id' => $id))->row();
$this->model_name->GetWhere('table2', array('idre' => $query->idre));
UPDATE:
3.
I use the following code true in model as mvc?
$id = $this->input->post('checked');
foreach ($id as $val) {
$query_check = $this->db->get_where(table3, array('id'=>$val));
$row = $query_check->row();
if($query_check->num_rows() > 0 || $row->id != $this->session->userdata('id')){
foreach ($query_check->result() as $value) {
$id_relation = $value->id_relation;
$this->db->where('idre', $idre)->delete(array(table3, 'table4'));
}
}
}
Whether this is a good example of mvc? How can fix 2 example above for good mvc?