php - 从数据库表中选择特定字段

标签 php mysql drupal-6

我有这段代码,它从数据库中选择内容类型,然后根据内容类型构建它的 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/

相关文章:

java - 将 MySQL 连接到 Apache nutch

drupal - 如何将许多现有文件与 drupal 文件字段关联起来?

php - 每个月选出一名得分最高的获奖者

php - 获取 sql 返回正确的帖子

php - 从 NSString 到 PHP 到 MySql 时如何处理回车?

php - 如何在android webview中保持网站 session

c# - 更好的是 : direct connection or through php for mysql database

Drupal Rules 一次性登录地址

templates - Drupal 6 中特定节点的自定义模板?

php - ajax - 如何执行一组特定的 AJAX 代码而不执行其他代码