我有这段代码,它从数据库中选择内容类型,然后根据内容类型构建它的 View 。
$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"');
但是当我需要使此代码仅显示特定内容类型时,它会显示每种内容类型。如何只显示选定的内容类型?
最佳答案
在 WHERE
子句中将 n
更改为 p
。
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')
关于php - 从数据库表中选择特定字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11828227/