Radu
Radu

Reputation: 8699

Custom query in drupal views - now can't sort

The view with the custom query is being displayed in the right sidebar titled "Most Downloaded" here: http://tf2huds.com. The view with the query generated by views is right below it.

To put in the custom query I'm using this code in the views.module file:

<?php
function views_views_pre_execute(&$view) {
   if($view->name=="hud_downloads") {
     $view->build_info['query']="SELECT node.nid AS nid, 
         node.title AS node_title, 
         SUM(pubdlcnt.count) AS pubdlcnt_count 
         FROM node node 
         LEFT JOIN pubdlcnt pubdlcnt ON node.nid = pubdlcnt.nid  
         WHERE (node.type in ('huds')) AND (node.status <> 0) 
         GROUP BY node.nid ORDER BY pubdlcnt_count DESC";
     }
}
?>

Pastebins:

Any idea why I can't sort my view? Thanks in advance.

Upvotes: 0

Views: 808

Answers (1)

googletorp
googletorp

Reputation: 33275

You cannot sort the view, because you are hard-coding the SQL to always be the same. So when you change the SQL with views, via the table, it get's overwritten by your views_views_pre_execute function.

Upvotes: 2

Related Questions