views:

28

answers:

1

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.

+1  A: 

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.

googletorp
Thanks for the quick answer. Is there any way I can restore that functionality and keep my custom query?
Radu
This is the query for the one I didn't overwrite: SELECT node.nid AS nid, node.title AS node_title, 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) ORDER BY pubdlcnt_count DESCBeing new to Drupal and Views I figured that changing it a bit wouldn't have an effect on the usability of the view.
Radu