-3
$query="SELECT MINUTE (ETA - STA) 
FROM `FlightSchedule` WHERE `flightNum_arr`='".$flightNum_arr."';";

$delay=ejecutar_query($query);

$query = "UPDATE `FlightSchedule` 
SET `delay`='".$delay."' 
WHERE `flightNum_arr`='".$flightNum_arr."';";

$result=ejecutar_query($query);

Instead of saving the minutes values, it saves Resource id#. How to fix this issue?

4

2 回答 2

1

在您的代码中,$delay不是行中的数据,而是代表结果的整个对象。

但是,您可以尝试在这样的一个语句中执行此操作:

update `FlightSchedule` set delay=(SELECT MINUTE (ETA - STA) 
FROM `FlightSchedule` WHERE `flightNum_arr`='".$flightNum_arr."');";

编辑:

试试这个来绕过 MySQL 所做的傻锁:)

update `FlightSchedule` set delay=(select * from (SELECT MINUTE (ETA - STA) 
FROM `FlightSchedule` WHERE `flightNum_arr`='".$flightNum_arr."'));";

编辑 2:(又名我应该测试我的查询,而不是仅仅在我的头顶上乱写它们......)

mysql> select * from updatetest;
+------+------+
| var1 | var2 |
+------+------+
|  450 |    1 |
|  100 |    5 |
+------+------+
2 rows in set (0.00 sec)

mysql> update
    updatetest set var2=
        (select * from
            (select var2 from updatetest where var1=100)
        updater);
Query OK, 1 row affected (0.00 sec)
Rows matched: 2  Changed: 1  Warnings: 0

mysql> select * from updatetest;
+------+------+
| var1 | var2 |
+------+------+
|  450 |    5 |
|  100 |    5 |
+------+------+
2 rows in set (0.00 sec)
于 2013-08-26T11:49:17.270 回答
1

您必须使用获取数据

$row = ejecutar_fetch_assoc($delay); // something like that but not sure

修改您的更新查询。

$query = "UPDATE `FlightSchedule` 
SET `delay`='".$row['delay']."' 
WHERE `flightNum_arr`='".$flightNum_arr."';";

还稍微修改选择查询。

$query="SELECT MINUTE (ETA - STA) AS delay
FROM `FlightSchedule` WHERE `flightNum_arr`='".$flightNum_arr."';";
于 2013-08-26T11:47:07.197 回答