当向 Drupal 站点的用户注册页面添加新字段时,新字段不会存储在“用户”表中,而是存储在它们自己的单独表中。我设置了一个自定义表单模块页面,用户可以在其中根据年龄、性别、如果他们是学生以及他们是否选择在绰号 Live 下接收消息来选择哪些人接收他们的消息。我以前从未在 mySQL 查询中使用过“join”,所以我不确定 Drupal 数据库 API 的适当语法是什么。这是我目前拥有的:
$query = db_select("field_data_field_age", "a");
$query->join("field_data_field_gender", "g", "a.entity_id = g.entity_id");
$query->join("field_data_field_phone_number", "p", "a.entity_id = p.entity_id AND g.entity_id = p.entity_id");
$query->join("field_data_field_student", "s", "a.entity_id = s.entity_id AND g.entity_id = s.entity_id AND p.entity_id = s.entity_id");
$query->join("field_data_field_live", "l", "a.entity_id = l.entity_id AND g.entity_id = l.entity_id AND p.entity_id = l.entity_id AND s.entity_id = l.entity_id");
$query->groupBy("p.entity_id");
$query->fields("p", array("field_phone_number_value"))
->condition("a.field_age_value", $values["age_lower"], >=)
->condition("a.field_age_value", $values["age_upper"], <=)
->condition("l.field_live_value", "Yes", =)
->condition("g.field_gender_value", values["gender"], =);
$phone_numbers = $query->execute();
这段代码破坏了我的网站,我不确定我做错了什么。同样,我尝试在“multiple joins mysql”下搜索 Google,但没有找到专门处理 Drupal 数据库 API 的任何内容。任何帮助将不胜感激,谢谢!