0) {
$query = "SELECT cid.field_cantus_id_value, off.field_office_value, gen.field_genre_tid, fea.field_feast_tid, seq.field_sequence_value, pos.field_position_value, f.field_folio_value, s.entity_id, n.title FROM field_data_field_source s
INNER JOIN node n ON s.entity_id=n.nid
LEFT JOIN field_data_field_folio f ON s.entity_id=f.entity_id
LEFT JOIN field_data_field_sequence seq ON s.entity_id=seq.entity_id
LEFT JOIN field_data_field_feast fea ON s.entity_id=fea.entity_id
LEFT JOIN field_data_field_office off ON s.entity_id=off.entity_id
LEFT JOIN field_data_field_genre gen ON s.entity_id=gen.entity_id
LEFT JOIN field_data_field_position pos ON s.entity_id=pos.entity_id
LEFT JOIN field_data_field_cantus_id cid ON s.entity_id=cid.entity_id
WHERE s.field_source_nid=$srcnid
ORDER BY f.field_folio_value, seq.field_sequence_value";
$result = db_query($query)->fetchAll();
foreach ($result as $item) {
$nid = $item->entity_id;
$title = $item->title;
$fol = $item->field_folio_value;
$seq = $item->field_sequence_value;
$off = $item->field_office_value;
$cid = $item->field_cantus_id_value;
$genId = $item->field_genre_tid;
$term= taxonomy_term_load($genId, 'genre');
$gen=$term->name;
$feaId = $item->field_feast_tid;
$term= taxonomy_term_load($feaId, 'feast');
$fea=$term->name;
$pos = $item->field_position_value;
$rows[]= array($fol,$seq,$fea,$off,$gen,$pos,"".$title,$cid);
}
$header = array ('Folio','Seq','Feast','Office','Genre','Position','Incipit','Cantus ID');
$variables = array('header' => $header, 'rows' => $rows, 'attributes' => array(), 'caption' => NULL, 'colgroups' => array(), 'sticky' => TRUE, 'empty' => '');
$src=node_load($srcnid);
print "