1

我有这段代码,它从数据库中选择内容类型,然后根据内容类型构建它的视图。

$q = db_query('SELECT n.nid, n.title, r.body, f.filename
FROM {node} n
INNER JOIN {node_revisions} r ON n.vid = r.vid
INNER JOIN {content_type_brands} p ON p.nid = n.nid
INNER JOIN {files} f ON f.fid = p.field_deyat_pic_fid
WHERE n.type =  "brands"');

但是当我需要使此代码仅显示特定内容类型时,它会显示每种内容类型。我该怎么做才能仅显示选定的内容类型?

4

1 回答 1

3

在您的条款中更改n为。pWHERE

SELECT  n.nid, n.title, r.body, f.filename
FROM    {node} n
            INNER JOIN {node_revisions} r 
                ON n.vid = r.vid
            INNER JOIN {content_type_brands} p 
                ON p.nid = n.nid
            INNER JOIN {files} f 
                ON f.fid = p.field_deyat_pic_fid
// WHERE    p.type =  'brands'
WHERE p.type IN ('brand1','brand1','brand1')
于 2012-08-06T12:29:40.753 回答