字段列表中的列'nid'在Drupal6中是不明确的查询

时间:2011-10-25 12:59:31

标签: php mysql drupal drupal-6 drupal-modules

我正在尝试为显示内容创建一个块,但是我收到了这个错误:

user warning: Column 'nid' in field list is ambiguous query: SELECT nid, title FROM node nd LEFT JOIN content_type_efemerides cte ON ( nd.nid = cte.nid ) WHERE type = '0' AND field_efemerides_fecha_value = '1' in D:\Webserver\htdocs\intranet\sites\all\modules\efemerides_form\efemerides_form.module on line 12.

第12行有这段代码:

8 $today = getdate();
9 $type = "efemerides";
10
11 $query = "SELECT nid, title FROM  {node} nd LEFT JOIN {content_type_efemerides} cte ON ( nd.nid = cte.nid ) WHERE type = '%d' AND field_efemerides_fecha_value = '%d'";
12 $query_result = db_query($query, $type, $today);

1 个答案:

答案 0 :(得分:4)

select语句中的nid不明确(如错误消息所述),您只需要使用表别名限定它:

$query = "SELECT nd.nid, nd.title FROM  {node} nd LEFT JOIN {content_type_efemerides} cte ON ( nd.nid = cte.nid ) WHERE type = '%s' AND field_efemerides_fecha_value = '%s'";

此外,字符串替换也应使用%s代替%d%d为小数)