php - codeigniter how to display data base query result as a message in the view and how to redirect same function? -
my model looks:
public function addmobileaction() { $mobile = $this->input->post('mobile',true); $qry = 'select * mobile mobile='.$this->db->escape($mobile); $query =$this->db->query($qry); $value=$query->num_rows(); if($value == 0) { $mobile_id=$this->db->select('mobile_id')->order_by('mobile_id','desc')->limit(1)->get('mobile')->row('mobile_id'); $mid=$mobile_id+1; $sql = "insert mobile (mobile,mobile_id) values(".$this->db->escape($mobile).",".$this->db->escape($mid).")"; $this->db->query($sql); return "registered sucessfully! id is: ".$mid; } else { $mobile_id=$this->db->select('mobile_id')->where('mobile', $mobile)->get('mobile')->row('mobile_id'); return "already registered! id: ".$mobile_id; } }
my controller is
public function addmobileprocess() { if(($this->session->userdata('username')!="")) { $this->load->library('form_validation'); $this->form_validation->set_rules('mobile', 'mobile', 'xss_clean|min_length[10]|required'); if($this->form_validation->run() == false) { $this->home(); } else { $result= $this->contentmodel->addmobileaction(); $datasucess['mobileid']=$result; $data['sucess'] = $this->load->view('sucess', $datasucess, true); $this->load->view('index',$data); } } else { $this->load->view('login'); } }
my need have take both return values model , display message in view based on condition checked on model, here view same view data posted.
that means after data submission have redirect function call view , have display "already registered! id: ".$mobile_id; if mobile number registered , "registered sucessfully! id is: ".$mid; if mobile number new.
how redirection done? modification have done. new kind of situation.thanking in advance.
public function addmobileaction() { $mobile = $this->input->post('mobile',true); $qry = 'select * mobile mobile='.$this->db->escape($mobile); $query =$this->db->query($qry); $value=$query->num_rows(); if($value == 0) { $mobile_id=$this->db->select('mobile_id')->order_by('mobile_id','desc')->limit(1)->get('mobile')->row('mobile_id'); $mid=$mobile_id+1; $sql = "insert mobile (mobile,mobile_id) values(".$this->db->escape($mobile).",".$this->db->escape($mid).")"; $this->db->query($sql); return true; } else { $mobile_id=$this->db->select('mobile_id')->where('mobile', $mobile)->get('mobile')->row('mobile_id'); return "already registered! id: ".$mobile_id; } }
//controller
public function addmobileprocess() { if(($this->session->userdata('username')!="")) { $this->load->library('form_validation'); $this->form_validation->set_rules('mobile', 'mobile', 'xss_clean|min_length[10]|required'); if($this->form_validation->run() == false) { $this->home(); } else { $result= $this->contentmodel->addmobileaction(); //check if result true or not , perform conditions per condition } } else { $this->load->view('login'); } }
Comments
Post a Comment