在剩余金额而不是实际金额中存储负值?

时间:2015-09-29 12:55:24

标签: php mysql codeigniter

我有一张桌子(即)paymentsPay_IDOrder_IDUser_IDBank_NameAccount_No,{{1} },Total_AmountPaid_AmountRemaining_Amount 我用这段代码更新了表格

DateTime

这里在$ sess_id中我将MAX(public function update() { $sess_id = $this->session->userdata('tot_amnt'); $Bank_Name = $this->input->post('Bank_Name'); $Account_No = $this->input->post('Account_No'); $Paid_Amount = $this->input->post('Paid_Amount'); $qq = "UPDATE `payments` SET Bank_Name = '".$Bank_Name."', Account_No = '".$Account_No."', Paid_Amount = '".$Paid_Amount."', Remaining_Amount = '".$sess_id."' - '".$Paid_Amount."' ORDER BY `DateTime` DESC LIMIT 1"; return $this->db->query($qq); } )存储在控制器(i-e)中的DateTime表中

payments

现在每件事情都运转正常,但它给我看了两个错误, 第一个错误:pay_model行No:22中的数组到字符串转换:

$query = $this->db->query('SELECT `Total_Amount` FROM `payments` WHERE     `DateTime` = (SELECT MAX(DateTime) FROM `payments`)')->result(); 
$new_data=array(
  'tot_amnt' => $query
  );
$this->session->set_userdata($new_data);

和第二个错误:它在Remaining_Amount中插入负值,如-200或其他。我用它附上快照..谢谢。 快照是: enter image description here enter image description here enter image description here

1 个答案:

答案 0 :(得分:0)

我猜您的$sess_id实际上是一个数组,因此会打印单词Array,这就是Remaining_Amount中的计算类似于Array - 200 = -200的原因。

我发现$sess_id来自$sess_id = $this->session->userdata('tot_amnt');,所以您可能已经分配了tot_amnt

$tot_amnt = array(
                   'tot_amnt'  => 1112
               );
$this->session->set_userdata($tot_amnt);

相反,您可以一次添加userdata一个值:

$this->session->set_userdata('tot_amnt ', 1112);