我正在尝试为显示内容创建一个块,但是我收到了这个错误:
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);
答案 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
为小数)