gpt4 book ai didi

codeigniter - 如果输入文本为空,如何传递零?

转载 作者:行者123 更新时间:2023-12-02 04:02:53 25 4
gpt4 key购买 nike

我的计算遇到了一些问题,当我传递折扣和借记值时,它正在执行其工作,但是当折扣和借记值为零时,它会返回空白页。这是我的模型.. CODEIGNITER。

function createInvoice() {
$this->load->helper('date');
$date = date('Y-m-d H:i:s');
$data = array(
'Date' => $date,
'Terms_Of_Payment' => $this->input->post('termsOfPayment'),
'Sub_Total' => $this->input->post('subTotal'),
'Total' => $this->input->post('total') - $this->input->post('discount'),
'Discount' => $this->input->post('discount'),
'Debit' => $this->input->post('debit'),
'Payment_Cridet' => $this->input->post('total') - $this->input->post('debit') - $this->input->post('discount'),
'Note' => $this->input->post('note'),
'Customer_ID' => $this->input->post('customerId'),
'User_ID' => $this->session->userdata('id'));

$this->db->insert('invoice', $data);
return ($this->db->affected_rows() != 1) ? false : true;
}

最佳答案

最好的方法是使用三元运算符。

$subtotal = $this->input->post('subTotal') == "" ? 0 : $this->input->post('subTotal');

如果你的 php 版本是 7.0> 则使用

$subtotal = $this->input->post('subTotal') ?? 0;

关于codeigniter - 如果输入文本为空,如何传递零?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41055159/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com