字段名称相同时的 SQL 连接
我在节点和 url_alias 中都有字段语言".当我进行转储时,第二个语言"变量会覆盖第一个.如何识别这两个变量?
I have field "language" in both node and url_alias. When I do a dump, the second "language" variable overwrites the first one. How can I identify both variables?
$string = "SELECT * FROM {node} as node " .
" LEFT JOIN {url_alias} as url " .
" ON url.src = CONCAT('node/', node.nid) " .
" ORDER BY node.type , node.nid " ;
$result= db_query($string);
while ($row = db_fetch_object($result)){
echo $row->language;
var_dump($row);
推荐答案
在 SELECT
子句中明确指定列名,而不是使用 *
,并给出任何重复的列命名别名.例如,
Specify the column names explicitly in your SELECT
clause rather than using *
, and give any duplicate column names an alias. E.g.,
SELECT node.nid,
node.language as NodeLanguage,
url.language as UrlLanguage
FROM {node} as node
LEFT JOIN {url_alias} as url
ON url.src = CONCAT('node/', node.nid)
ORDER BY node.type , node.nid
相关文章