[英]Insert PHP variable into SQL Select query output
I have a dynamic php variable that I would like to join to every row in a column of an sql query. 我有一个动态php变量,我想加入到sql查询的每一行中。 I know that the following works to add as static variable:
我知道以下内容可以添加为静态变量:
$output = "SELECT
'example' as extra_column,
order_date as order_date
FROM $order_table"
would return: 会返回:
extra_column order_date
example 01/01/2017
example 02/01/2017
example 02/01/2017
but I cant figure out how to make the field in the extra column dynamic, for example I've tired 但我想不出如何使额外列中的字段动态化,例如,我已经累了
$output = "SELECT
'"$dynamic_variable"' as extra_column,
order_date as order_date
FROM $order_table"
but this breaks the query, anyone got any ideas? 但这打破了查询,任何人有任何想法吗?
尝试使用点将字符串连接起来。
$output = "SELECT '".$dynamic_variable."' as extra_column, order_date as order_date FROM $order_table"
You have syntax error. 您有语法错误。
There should be dots when you concat string and variable. 连接字符串和变量时,应该有点。
$dynamic_variable = 'example';
$output = "SELECT
'" . $dynamic_variable . "' as extra_column,
order_date as order_date
FROM $order_table";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.