How to share the total money among users in the encoder

I am working on one simple program. If I insert two values, rupees and roommates, I have to split the rupees / roommate.

How do I get the result? For example, I have 5 roommates, and I entered rupees = 500, and I want it to appear on the page, for example, 100 times 5 times?

// THIS IS THE MODEL public function insertModel() { $data = array( 'm_rupee' => $this->input->post('m_rupee'), 'rommmate' => $this->input->post('roommate') ); $this->db->insert('tbl_money',$data); return; } // THIS IS THE CONTROLLER public function insertDate() { $this->MoneySplitter->insertModel('$data'); redirect('MoneySpliterController'); } // THIS IS THE VIEW <form method="post" action="<?php echo base_url();>index.php/MoneySpliterController/insertDate"> <input type="text" name="m_rupee" /> <input type="text" name="rommmate" /> <input type="submit" value="save"> </form> 
+5
source share
1 answer

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

+4
source

All Articles