【问题标题】:how to divide total money among the users in codeigneter如何在codeigniter中的用户之间分配总资金
【发布时间】:2015-10-27 18:12:01
【问题描述】:

我正在开发一个简单的程序。如果我插入两个值,卢比和室友,我必须除以卢比/室友。

我将如何获得结果?比如我有5个室友,我输入了卢比=500,我想让它像100卢比一样显示在页面上5次?

// 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 次得到 100 卢比吗?”,你想在哪里展示这个,
  • 是的,我想将第一个输入框的值除以第二个输入框的值。我想将结果显示为希望你理解的人均金额..

标签: php codeigniter logic


【解决方案1】:

我希望这可以帮助您,请理解代码并尝试使用它来满足您的要求。祝你好运!

控制器文件。

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

<div><?php var_dump($info); ?></div>

参考:http://www.codeigniter.com/userguide2/tutorial/static_pages.html

【讨论】:

  • 先生,您能详细说明一下吗?我是codeigneter的新手。如何在视图中显示该数据。
猜你喜欢
  • 1970-01-01
  • 2011-08-03
  • 2021-12-14
  • 2018-09-11
  • 2013-05-22
  • 2017-12-13
  • 2014-01-24
  • 2018-08-20
  • 2012-03-30
相关资源
最近更新 更多