1

我需要用一个左连接$var!没有变量,代码可以工作:

$query->select('d.value AS department');
$query->join('LEFT', '#__jea_departments AS d ON d.id = p.department_id');

我尝试了输入变量的所有语法,但它不起作用!

$var="d.test";

$query->select('**$test** AS department');
$query->join('LEFT', '#__jea_departments AS d ON d.id = p.department_id');

我试过"$test" {$test}了,但它不起作用。

4

2 回答 2

0

您正在使用单引号。然后它不会将 $test 转换为 propper 值。使用双引号或使用 $test 。作为部门'

$test = 'd.test';
print '$test as department';  //will print: $test as department
print "$test as department";  //will print: d.test as department
print $test. ' as department';  //will print: d.test as department
于 2012-12-03T12:26:10.223 回答
0

您正在使用单引号传递字符串文字,这就是问题所在。PHP 不会在用单引号定义的字符串中插入变量。将它们更改为双引号以解决:

$query->select("$test AS department");

或者连接变量:

$query->select($test . ' AS department');

手册

与双引号和heredoc 语法不同,特殊字符的变量和转义序列在出现在单引号字符串中时不会被扩展。

于 2012-12-03T12:26:18.163 回答