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.

From: http://drupal.org/node/131031

$view = views_get_current_view();
 
// execute view query
$view->execute();
 
// results are now stored as an array in $view->result
$count = count( $view->result );
 
print "Showing <b>$count</b> results";

Comments

Your code really helped me alot....it 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 view..im guessing its like

$view = my_view_name; ?

You could use views_get_view().

So:
$view = views_get_view('my_view_name')

More info here http://api.drupal.org/api/views/views.module/function/views_get_view/5

Post new comment

The content of this field is kept private and will not be shown publicly.

Learn how to write custom Drupal modules

Does Drupal module development make your head explode and drive you crazy?

Why not learn from someone who has paved the way instead?

Sign up to Master Drupal 7 Module Development.

Hello!!

I am Blair Wadman and this is where I write about Drupal, PHP, CSS etc

Stuff

Syndicate

Syndicate content

© Blair Wadman
2005 - 2011