简体   繁体   English

简单的mysql查询来访问Drupal 7中的数据字段

[英]simple mysql query to access data fields in Drupal 7

I have got some trouble with Drupal 7. What I want to do is read out all field_data_fields of one objects with php. 我在Drupal 7中遇到了一些麻烦。我想做的就是用php读取一个对象的所有field_data_fields。

Example: I need to show a CAR Entry and I need to access field_data_field_speed field_data_field_size 示例:我需要显示CAR条目,并且需要访问field_data_field_speed field_data_field_size

etc. 等等

The Problem is that I can't find out where all this field entries are connected to an object id. 问题是我找不到所有这些字段条目都连接到对象ID的位置。 Is there maybe a very easy solution to get all fields connected to an object id? 是否有一个非常简单的解决方案来使所有字段都连接到对象ID?

Anyone who knows Drupal and can help me? 知道Drupal并可以帮助我的人吗? :) Thx :) 谢谢

Sounds like the EntityFieldQuery should save you lots of time 听起来像EntityFieldQuery应该可以节省很多时间

EDIT: Adding a sample you could refer to 编辑:添加示例,您可以参考

$query = new EntityFieldQuery();

$query
  ->entityCondition('entity_type', 'node')
  ->entityCondition('bundle', 'car')
  ->propertyCondition('status', 1); //Remove to include unpublished content
$result = $query->execute();

$nids = array_keys($result['node']);

if(!empty($nids)){

    $nodes = node_load_multiple($nids);

    foreach($node as $car_node){
        $node_wrapper = entity_metadata_wrapper('node', $car_node);

        //FINALLY! Here we can get the value of the field you need
        $size = $node_wrapper->field_size->value();

    }
}

It's much easier to use "views" module than to write your own queries. 使用“视图”模块比编写自己的查询要容易得多。 It's, let's say, standard in Drupal development: 可以说,这是Drupal开发的标准:

https://www.drupal.org/project/views https://www.drupal.org/project/views

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM