【发布时间】:2015-10-21 15:30:25
【问题描述】:
我创建了一个二维数组 order_details 具有以下结构:
| order_id | product_id |
+==========+============+
| 1 | 2 |
+----------+------------+
| 1 | 3 |
+----------+------------+
| 2 | 4 |
+----------+------------+
| 3 | 2 |
+----------+------------+
我使用 post 方法将这个数组发送到一个 php 文件。
在 php 文件中,我使用以下代码来存储数组:
$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
$array = $request;
我想使用这样的数组在 mysql 中执行更新查询:
UPDATE table_ex SET status='completed' WHERE order_id IN array.order_id AND product_id IN array.product_id
查询前的Table_ex如下:
| order_id | product_id | status |
+==========+============+=========+
+----------+------------+---------+
| 5 | 4 | nothing |
+----------+------------+---------+
| 6 | 2 | nothing |
+----------+------------+---------+
| 1 | 2 | nothing |
+----------+------------+---------|
| 1 | 3 | nothing |
+----------+------------+---------+
| 2 | 4 | nothing |
+----------+------------+---------+
| 3 | 2 | nothing |
+----------+------------+---------+
更新后的 table_ex 应该如下所示:
查询前的Table_ex如下:
| order_id | product_id | status |
+==========+============+===========+
| 5 | 4 | nothing |
+----------+------------+-----------+
| 6 | 2 | nothing |
+----------+------------+-----------+
| 1 | 2 | completed |
+----------+------------+-----------+
| 1 | 3 | completed |
+----------+------------+-----------+
| 2 | 4 | completed |
+----------+------------+-----------+
| 3 | 2 | completed |
+----------+------------+-----------+
你能帮帮我吗!
提前致谢,
詹尼斯
【问题讨论】:
-
你的问题是什么?
-
我添加了更多细节以更具体。你可以再检查一遍。
-
我还是没看到问题。尝试添加一个问号:P
-
对所有这些混乱感到抱歉。我的问题:有没有办法从第一个表中获取每一对(order_id,product_id),以便在 php 文件中 mysql 查询的 where 子句中使用它?
-
最后@syck 的回答对我有用。谢谢大家。
标签: php mysql arrays angularjs