Joomla查询选择左连接和$ var

时间:2012-12-03 12:18:39

标签: php mysql joomla left-join

我需要使用$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},但它不起作用。

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

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

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

或者连接变量:

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

来自Manual

  

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