Skip to content

Instantly share code, notes, and snippets.

@underhilllabs
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save underhilllabs/9675191 to your computer and use it in GitHub Desktop.
Save underhilllabs/9675191 to your computer and use it in GitHub Desktop.
query db with a join, using db_select. #drupal
<?php
function dance_code_show_sessions() {
$rows = array();
$query = db_select('node', 'n');
$query->join('field_data_field_session_date', 'sd', 'n.nid = sd.entity_id');
$query->condition('n.type', 'fundamentals_session')
->condition('n.status', 1)
->fields('sd', array('field_session_date_value'))
->fields('n', array('title','nid'))
->orderby('sd.field_session_date_value', 'DESC');
$res = $query->execute() ;
foreach ($res as $row) {
$rows[] = array(
$row->title,
date("Y-m-d",$row->field_session_date_value),
'<a href="/session-supervisors/' . $row->nid . '">Select Session Supervisors</a>',
);
}
$table_output = array(
'#theme' => 'table',
'#rows' => $rows,
'#header' => array('Session Title', 'Session Date', 'Action'),
);
return $table_output;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment