我试图用 php 中的 sql 结果创建一个字段。我正在尝试使用字段“manifestacionType”创建条件并与值“compuesta”进行比较。
问题是我不知道该怎么做。我认为问题在于 n.manifestacionType 无法访问该字段的实际值并且从不进行比较。我尝试了一些类似 ['und']['value'] 的东西,使用 ->node,但没有任何效果!我不知道要 build 这个。我很绝望!
这是我的代码:
$query = db_select('node', 'n')
->fields('n', array('nid', 'title'))
->condition('n.type', 'manifestacion_cultural', '=')
->condition('status', 1,'=')
**->condition('n.manifestacionType', 'compuesta', '=')**
->orderBy('title');
$result = $query->execute()->fetchAllKeyed();
return $result;
这样做的结果是什么,如果我删除 ** 中的条件,我会收到状态=1(已发布)的所有“manifestacion_culture”。我需要添加一个过滤器,其条件是仅接收“manifestacionType”(这是一个字段)=“compuesta”。很可能有一些更好的解决方案来创建字段或执行此查询的方法,但我不知道如何。
非常感谢!
最佳答案
我不知道我是否正确理解了你的问题,所以,如果不是你想要的,请纠正我:
您有一个名为“manifestacion Type”的字段,那么您想要获取内容类型为“manifestacion_culture”且“manifestacion Type”字段值等于“compuesta”的节点结果。
在这种情况下,您需要使用节点表和“manifestacion Type”字段表之间的联接来构建 db_select,请访问您的数据库并检查“manifestacion Type”字段表的名称,drupal 始终创建像这样的字段表:field_data_fiel_machine_name
$query = db_select('node', 'n')
->fields('n', array('nid', 'title'))
->condition('n.type', 'manifestacion_cultural', '=')
->condition('status', 1, '=');
->join('fiel_data_manifestacionType_table', 'mt', 'n.nid = mt.nid');
->condition('mt.fiel_manifestacionType_value', 'compuesta', '=');
->orderBy('n.title', 'ASC');
$result = $query->execute()->fetchAllKeyed();
关于php - 我如何构建 db_select, ->condition 将字段与 drupal 中的值与 php 进行比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51461075/