[SOLVED][Drupal Views] How to count the results of a View ?

| | 1 min read

Many Drupal users have been searching for a way to count the results of a View present in their Drupal sites. If you are looking for a method to count the results queried by one of your Views in your Drupal site then read on to find out the method to do that.

Here is the solution.

  • You could use the following sample code in your module to print the results
  • function get_view_rowcount(){
    
      $view = views_get_current_view();
      $page_total = count($view->result);
      if(isset($view->total_rows)){
        return "<p>Displaying " . $page_total . " of " . $view->total_rows . " total rows.</p>";
      } else {
        return "<p>Displaying " . $page_total . " of " . $page_total . " total rows.</p>";
      }
    }

  • A few Drupal 7 users have reported that "Global: Result summary" field present below the View header can do the same job

Hope that helps.

The easiest way to solve a Drupal issue is to hand it to the Drupal experts. We can provide a wide range of Drupal services to help you maintain and manage your Drupal websites. Get in touch with us to know more.