我希望这可以帮助你,请理解代码,并尝试使用它来满足您的要求.祝好运!
控制器文件.
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');
}
模型文件.
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