Skip to content

Instantly share code, notes, and snippets.

@lkacenja
Created November 14, 2013 17:37
Show Gist options
  • Save lkacenja/7470985 to your computer and use it in GitHub Desktop.
Save lkacenja/7470985 to your computer and use it in GitHub Desktop.
<?php
// Get All Airings BY Project Per Range
$start = 1383845472;
$end = 1384450272;
$query = db_select('field_data_field_om_airing_dates', 'dates');
$query->join('field_data_field_om_show_id', 'om_show', 'dates.entity_id=om_show.entity_id');
$query->join('field_data_field_om_show_project', 'project', 'om_show.field_om_show_id_value=project.entity_id');
$query->fields('project', array('field_om_show_project_nid'));
$query->addExpression('COUNT(field_om_show_project_nid)', 'airings');
$query->condition('dates.field_om_airing_dates_value', $start, '>=');
$query->condition('dates.field_om_airing_dates_value2', $end, '<=');
$query->groupBy('project.field_om_show_project_nid');
$query->orderBy('airings', 'DESC');
dpq($query);
$resource = $query->execute();
$result = $resource->fetchAll();
dsm($result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment