0
我的表名是預訂:如何自動更新phpmyadmin中的列
| reservation_id(pk)|人數|容量|
我希望當我輸入的人數比no_of_people列減去容量列 和能力列更新爲新的no_of_people。 請告訴我如何更新容量表?
模型視圖:
public function insert_into_db($people)
{
$sql = "INSERT INTO `reservation` (`no_of_people`) VALUES (?) ";
"SELECT *, `capacity`-`no_of_people` AS `capacity` FROM `reservation`";
$this->db->query($sql, array($people));
}
控制器視圖
public function insert_people()
{
$people =$this->input->post('no_of_people');
$this->Books_model->insert_into_db($people);
redirect('Booking_Controller/view');
}
視圖文件:
<form action="<?php echo base_url();?>index.php/Booking_controller/insert_people" method="POST">
<table>
<tr>
<td> <label for="no of people" class="col-sm-2 control-label"><td>Number Of People*</td></label>
</td>
<td> <input type = 'text' name='no_of_people'></td>
</tr>
<tr>
<td><input type='submit' class="btn btn-success" value="Book a Table"></td>
</tr>
</table>
請幫我看看,我所犯的錯誤?
這與phpmyadmin有什麼關係?無論如何,你可以在MySQL端使用觸發器來做到這一點。更多信息在這裏:[官方文檔](https://dev.mysql.com/doc/refman/5.0/en/trigger-syntax.html) –
爲什麼你將容量存儲在保留表中,這是一個動態值, 'SELECT SUM(no_of_people)as capacity FROM reservations' – nathanmac