When adding new fields to the user registration page of a Drupal site the new fields are not stored in the “User” table, but in their own individual tables. I have a custom form module page set up where the user can select which people receive their message based on Age, Gender, if they are a Student, and if they have chosen to receive message under the moniker Live. I have never used “join” before with a mySQL query so I am unsure what the appropriate syntax is for the Drupal Database API. This is what I currently have:
$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();
This code is breaking my site and I am unsure of what I am doing wrong. Again, I tried searching Google under “multiple joins mysql”, but didn’t find anything exclusively dealing with the Drupal Database API. Any help would be greatly appreciated, thanks!
The third-to-last line is missing a $ on the “values” variable.
Also, the operators >=, <=, and = need to be strings (in quotes).