Currently, I am working on a large scale project based on Drupal framework for the first time. And as much as I thought I've mastered working with drupal, I find myself with more challenges.
This time, the challenge was Views. Unfortunatelly, Views does not offer the flexibility to amend changes to its SQL queries which can be devastating sometimes. One of my tasks was to display a list of users who have recently published in a certain category, and the list of users needs to be unique.
With that, I found the best way is to utilize THEME_views_pre_execute(&$views) function, which allows me to manipulate with the SQL query to my own liking in my custom module, which worked wonderfully.
And here is another script that you can put in your block that will fetch result from the database, here it is:
$sql = "";
$output = '';
$nlimit = 5;
$result = db_query_range(db_rewrite_sql($sql), $uid, 0, $nlimit);
$output .= '<div class="item-list"><ul>' . "\n";
$output .= node_title_list($result);
$output .= '</ul></div>';
print $output;
Anyway, I am merely posting this as a future reference for myself.
Comments [1]