Without writing using any Drupal db functions, how can I display the total/count/number of results of a view in its Header?


Do you not mean these predefined value(s) in the Header area ?

Return a view's total_rows in Drupal 7 without php filter?

You could count the number of rows using PHP in views_pre_render() ... but I bet this is what the above is doing already ....

| improve this answer | |
  • I Googled long and hard and never saw your other post... thanks tenken! – Johnathan Elmore Jun 12 '12 at 13:35

No need to use any php code.

you need the token module to be enabled along with the view of course.

1) Go to the view in question. 2) Click "Add" next to either "Header" or "Footer" in the center of the view. 3) Choose "Global: Result summary" 4) Click "Apply (All displays)" 5) On the next screen, you can chose tokens to put into the "Display" area. Here are the tokens you can use:

@start -- the initial record number in the set @end -- the last record number in the set @total -- the total records in the set @name -- the human-readable name of the view @per_page -- the number of items per page @current_page -- the current page number @current_record_count -- the current page record count @page_count -- the total page count

Once you've chosen your options, click "Apply (All displays)".

7) You can put something like: Displaying @start - @end of @total.

Hope it helps.

| improve this answer | |

Warning: this tip requires enabling the core PHP Filter module, which opens up security concerns that could potentially allow the entry of PHP code into the site in ways that you may not want, if permissions are not configured correctly.

Here is how using the core PHP Filter module:

  1. In your view, add a header element of type Global PHP
  2. Then add this snippet to text/php field in the header

    <?php echo $view->total_rows; ?>

That should do it. There are a tonne more variables in the $view array.

Edit: As @Motot suggested, added security note.

| improve this answer | |
  • -1 for suggesting PHP filter without mentioning how huge risk it is. – Mołot Aug 17 '15 at 13:53

Not the answer you're looking for? Browse other questions tagged or ask your own question.