Number of results in a Drupal View

Find the number of results in a view. Add this snippet to the header or footer of the view, depending on where you want the number of results to be displayed.


  1. $view = views_get_current_view();
  3. // execute view query
  4. $view->execute();
  6. // results are now stored as an array in $view->result
  7. $count = count( $view->result );
  9. print "Showing <b>$count</b> results";


Your code really helped me saved much of my time...

Thank you very much....

Thanks for this!

Thanks for the code, how do i display count of a view in a place other than the guessing its like

$view = my_view_name; ?

Blair Wadman's picture

You could use views_get_view().

$view = views_get_view('my_view_name')

More info here

This works well for me and deals with the pager issues. Put this function in your custom module, rename / format as needed, and call it from your views-view--view_name_goes_here.tpl.php files.

function get_view_rowcount(){

$view = views_get_current_view();
$page_total = count($view-&gt;result);
return "<strong>Displaying " . $page_total . " of " . $view-&gt;total_rows . " total rows.</strong>";
} else {
return "<strong>Displaying " . $page_total . " of " . $page_total . " total rows.</strong>";

and it saved me much time...
I'm interested in your lesson book, but for many reasons (several modules has not yet porting on D7) i'm now developing on D6 version. Do you think it can be the same way useful for learn module building in D6?
Thanks for you answer.

New comments for this tutorial have been turned off.