Hope this helps you, please understand the code and try playing with it to suit your requirements. Good luck
Controller file.
public function index(){ $data["info"] = $this->mModel->getData(); $this->load->view('index.php', $data);//$data is the data you want to pass to the view. } public function insertData() { $amount= $this->input->post('m_rupee'); //500 rupee $roommates = count($this->input->post('roommate')); //5 roommates with data. $amountPerPerson = $amount / $roommates; //100 rupee per roomate. //Iterate the number of roommates. foreach($roommates as $row){ //Call the function in model that will save the data. $this->mModel->insertModel($amountPerPerson, $row); } redirect('MoneySpliterController'); }
Model file.
public function insertModel($amount, $data){ $tempData = array( 'm_rupee' => $amount, 'roommate' => $data ); $this->db->insert('tbl_money', $tempData); } public function getData(){ return $this->db->get('tbl_money')->result(); }
index.php
<div><?php var_dump($info); ?></div>
Link: http://www.codeigniter.com/userguide2/tutorial/static_pages.html
source share