sortable self prepared field in a view
rupat - March 27, 2008 - 01:58
in my module i made a port to for the views module with using the nodevote module (iam using drupal 4.7)
function mischungxl_views_tables() {
$tables['mischungxl_nodes'] = array(
'name' => 'mischungxl_nodes',
'join' => array(
'left' => array(
'table' => 'node',
'field' => 'nid'
),
'right' => array(
'field' => 'nid'
)
),
'avgvote' => array(
'name' => t('mischungxl: durchschnitt'),
'handler' => 'mischungxl_views_handler_field_avgvote',
'notafield' => TRUE,
'sortable' => TRUE,
'help' => t(''),
),
),
);
return $tables;
}As you can see i have now a field "mischungxl: durchschnitt"
this field is generated through this function:
function mischungxl_views_handler_field_avgvote($fieldinfo, $fielddata, $value, $data) {
$sql = 'SELECT avg(vote) FROM `nodevote` WHERE nid='.$data->nid.' GROUP BY nid';
$result = db_query($sql);
if (mysql_affected_rows() == 1) {
$row=mysql_fetch_row($result);
return round($row[0],2);
} else return '-';
}if i set this field to sortable and klick on the table headline to sort. i get an error
user warning: Unknown column 'mischungxl_nodes_avgvote' in 'order clause'
how can i add the functionality ???
