插入并选择一个就绪值

时间:2014-12-17 05:03:38

标签: php mysql

我想在这里做的是向表中插入一些值,但该值来自另一个表。

但是,有一些价值可以发布。

  $reference_no = $_POST ['reference_no']
  $location_id = $_SESSION ['location_id']

  INSERT INTO infistall_location_stock_collect_update (package, quantity, location_id)
      SELECT product_id, quantity, '...'
      FROM orders_history
      WHERE reference_no = '$reference_no'

如何将$ location_id放入SELECT查询?

由于

2 个答案:

答案 0 :(得分:1)

INSERT INTO infistall_location_stock_collect_update (package, quantity, location_id)
SELECT product_id, quantity, '$location_id'
FROM orders_history
WHERE reference_no = '$reference_no'

答案 1 :(得分:0)

尝试引用列

$reference_no = $_POST ['reference_no']
$location_id = $_SESSION ['location_id']

INSERT INTO infistall_location_stock_collect_update (package, quantity, location_id)
  SELECT product_id, quantity, '(".$location_id.")' as location_id
  FROM orders_history
  WHERE reference_no = '$reference_no'

快乐编码..