我有以下代码:
$do_id=$_GET['id'];
$new_workorder=$_GET['workorder'];
//get current workorder on file for record that will be updated
$query = "SELECT workorder FROM jvltodos WHERE id = '$do_id' LIMIT 1";
$bla = mysql_query($query);
$workorder_old = mysql_fetch_row($bla);
//get record for workorder on file that will have the new workorder
$query = "SELECT id FROM jvltodos WHERE workorder = '$new_workorder' LIMIT 1";
$bla = mysql_query($query);
$id_fix = mysql_fetch_row($bla);
if (isset($new_workorder) && $new_workorder!=$workorder_old) {
//update the changed record
$query = "UPDATE jvltodos
SET workorder={$new_workorder}
WHERE id = {$do_id}";
$result = mysql_query($query);
//update the record that had the old workorder
$query = "UPDATE jvltodos
SET workorder={$workorder_old}
WHERE id = {$id_fix}";
$result = mysql_query($query);
}
我将 'id' 和 'workorder' 传递到 url,所以我先获取它们。有了这个,我将带有“id”的记录更新为新的“工作订单”。到目前为止,一切都很好。但我想找到具有该“工作订单”的记录,并使用旧“ID”中的“工作订单”对其进行更新。(简单来说:当我增加/减少'workorder'时,我想切换两条记录)对我来说它看起来很简单,但它不起作用。第一件事(使用新的工单更新 id 有效.. 但其他记录保持不变.. 它保留了已经存在的工单) 我错过了什么?(一定很简单,我只是忽略了。)