在“new_payment”表和“new_reservation”表中,每一行(付款)都有一个 res_id(new_reservation 中的 PK 和 new_payment、CASCADE、CASCADE 中的 reser、FK)。我必须填写 3 个输入框。
总账单:[ ]
以前支付: [ ]
到期金额: [ ]
当用户输入房间号并提交时,控制器调用'search_by_room_number'模型,然后模型,
- 从 new_reservation 表返回“总计”
- 将 new_reservation 表中的“res_id”返回到名为 $res_id 的变量中
- 使用该 $res_id,我在 new_payment 表中查找以前的“paid_amount”
- ...和 new_payment 表中的“due_amount”
但出乎意料的是,出现了以下错误:
A PHP Error was encountered
Severity: Notice
Message: Array to string conversion
Filename: models/payments_model.php
Line Number: 16
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: models/payments_model.php
Line Number: 18
A PHP Error was encountered
Severity: Notice
Message: Array to string conversion
Filename: models/payments_model.php
Line Number: 16
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: models/payments_model.php
Line Number: 18
模型:
function search_by_room_number($room_number) {
$query = $this->db->query("SELECT total FROM new_reservation WHERE room_number = '$room_number' AND payment_status = 'Pending' LIMIT 1"); // Line 16
$row = $query->row();
return $row->total; // Line 18
$res_id='';
$query = $this->db->query("SELECT res_id FROM new_reservation WHERE room_number = '$room_number' AND payment_status = 'Pending' LIMIT 1");
$row = $query->row();
$res_id = $row->res_id;
$query = $this->db->query("SELECT paid_amount FROM new_payment WHERE res_id = '$res_id' LIMIT 1");
$row = $query->row();
return $row->paid_amount;
$query = $this->db->query("SELECT due_amount FROM new_payment WHERE res_id = '$res_id' LIMIT 1");
$row = $query->row();
return $row->due_amount;
}
控制器:
function search_room_number() {
$popRoomNumbers = $this->input->post('room_number');
$totalBill['total'] = $this->payments_model->search_by_room_number($popRoomNumbers);
$previouslyPaid['paid_amount'] = $this->payments_model->search_by_room_number($popRoomNumbers);
$dueAmount['due_amount'] = $this->payments_model->search_by_room_number($popRoomNumbers);
$tmpFormData=array_merge($totalBill, $previouslyPaid, $dueAmount);
$this->load->view('/main/new_payment', $tmpFormData);
}
看法:
<?php $attr = array(
'name' => 'totalBill',
'id' => 'totalBill',
'class' => 'span2',
'readonly'=>'true',
'value' => $total
);
echo form_input($attr);
?>
<?php $attr = array(
'name' => 'previouslyPaid',
'id' => 'previouslyPaid',
'class' => 'span2',
'readonly'=>'true',
'value' => $paid_amount
);
echo form_input($attr);
?>
<?php $attr = array(
'name' => 'dueAmount',
'id' => 'dueAmount',
'class' => 'span2',
'readonly'=>'true',
'value' => $due_amount
);
echo form_input($attr);
?>