annotate sites/all/modules/views/help/get-total-rows.html @ 2:b74b41bb73f0

-- Google analytics module
author danieleb <danielebarchiesi@me.com>
date Thu, 22 Aug 2013 17:22:54 +0100
parents ff03f76ab3fe
children
rev   line source
danielebarchiesi@0 1 The flag $view->get_total_rows is used to force the query of the view to calculate the total number of results of the set.
danielebarchiesi@0 2
danielebarchiesi@0 3 This parameter is TRUE by default in views that get all the results (no limit) or those which have a pager, so you always have the $view->total_rows variable populated in those cases.
danielebarchiesi@0 4 But when you have a view that gets only a given number of results and no pager, the count query is not executed by default so you have to force it, i.e. in the hook_views_pre_execute so you have $view->total_rows populated for later use.
danielebarchiesi@0 5
danielebarchiesi@0 6 This code will help you do that.
danielebarchiesi@0 7
danielebarchiesi@0 8 <pre>
danielebarchiesi@0 9 &lt;?php
danielebarchiesi@0 10 function my_module_views_pre_execute(&$view) {
danielebarchiesi@0 11 if ($view->name == 'my_view' && $view->current_display == 'my_display') {
danielebarchiesi@0 12 $view->get_total_rows = TRUE;
danielebarchiesi@0 13 }
danielebarchiesi@0 14 }
danielebarchiesi@0 15 ?&gt;
danielebarchiesi@0 16 </pre>