Hi,

I would like to print out the total amount of nodes in a view in the page header of a view. I'm using views fastsearch to implement a site search and want to display

"Your search for keyword returned X results"

How can I insert the amount of nodes in my list into X.

Thanks,
Gary

Comments

merlinofchaos’s picture

Status: Active » Fixed

If you're using the pager, I believe you can look in the global variable (use global $pager_total) with the index of your element ID which is probably 0. So in most cases,

  global $pager_total;
  print $pager_total[0] . ' results';
asak’s picture

Status: Fixed » Needs work

@merlinofchaos: This does calculate something.. but not the correct result.

In a table view with 4 (or 5) results i'm getting a "1" in the $pager_total.
With 17 results i'm getting "2".

I have no idea what this is calculating ;)

How do I know what is the "Element ID" ?

asak’s picture

Ok i get it - i'm getting the number of PAGES and not the number of NODES.

Solution anybody (i know no PHP...) ?

Thanks!

merlinofchaos’s picture

The element ID is probably 0. $pager_total might be giving the total number of pages, though I thought it gave total results. Looking at the code, I see I should've given $pager_total_items.

Sorry about that.

asak’s picture

Hey merlin, that doesn't seem to work... Any other ideas? ;)

Thanks!

asak’s picture

Status: Needs work » Fixed

Very sorry. this works perfectly. thank you.

To display num. of nodes:

<?php
  global $pager_total_items;
  print $pager_total_items[0] . ' results';
?>

To display num. of pages:

<?php
  global $pager_total;
  print $pager_total[0] . ' results';
?>
Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

mattbk’s picture

Thanks! For the record, this works in Drupal 7/D7 as well.

<?php
global $pager_total_items;
echo "<h2>", $pager_total_items[0] . " upcoming events";
?>