将新字段添加到 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 的内容。任何帮助将不胜感激,谢谢!
最佳答案
倒数第三行的“values”变量上缺少 $。
此外,运算符 >=、<= 和 = 必须是字符串(用引号引起来)。
关于database - Drupal 7 - 查询中的多个连接给我带来了麻烦,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10590995/