查询中的行可以是一个或多个(最多 100 行),如果查询输出只有一行数据,则更新查询工作正常,但是当输出包含多行数据时,只会更新所选行的最后一行,我错过了什么?
一些背景:员工需要从一个位置移动到另一个位置,插入查询将数据写入数据库,但将 RECEIPT 日期留空。许多员工可以从一个地点被释放到另一个地点......这发生在不同的形式上,并且工作得很好。
现在收件人必须接受这些员工,更新查询在提交表单后在后台运行,它所做的只是在 $move_receipt_date 字段中输入今天的日期 ($d)。但正如我之前提到的,在我的更新查询中只有最后一行受到影响......
下面是获取数据和更新查询的选择查询,非常简单:
<?php
include("../../xxx.xxx");
$cxn = mysqli_connect($host,$user,$password,$dbname)
or die ("Couldn't connect to server.");
$query = "SELECT `move_id`,`empl_no`,`empl_jc_code` AS old_jc_code,`new_jc_code`,`move_date`,`move_receipt_date`,`move_reason`
FROM `empl_movement`
WHERE `new_jc_code` = '$empl_jc_code' AND `move_receipt_date` = 0";
$result = mysqli_query($cxn,$query)
or die ("Couldn't execute query. "
.mysqli_error($cxn));
echo "<table><br>
<tr>
<th>Move ID</th>
<th>Employee No</th>
<th>Old JC Code</th>
<th>New JC Code</th>
<th>Release Date</th>
<th>Receipt Date</th>
<th>Reason for Move</th>
</tr>";
while($row = mysqli_fetch_assoc($result))
{
extract($row);
echo "<tr>'n
<td>$move_id</td>'n
<td>$empl_idno</td>'n
<td>$old_jc_code</td>'n
<td>$new_jc_code</td>'n
<td>$move_date</td>'n
<td>$move_receipt_date</td>'n //this is the field that will be updated
<td>$move_reason</td>'n
</tr>'n";
}
echo "</table><br>"; ?>
<?php
include("../../xxx.xxx");
$cxn = mysqli_connect($host,$user,$password,$dbname)
or die ("Couldn't connect to server.");
$query = "UPDATE `empl_movement` SET `move_receipt_date` = '$d'
WHERE `move_id` = '$move_id'";
$result = mysqli_query($cxn,$query)
or die ("Couldn't execute query. "
.mysqli_error($cxn));
?>
因为在查询中,您只更新一个字段,即empl_movement。