0

I'm actually trying get the count of total rows retrieved by view. When I added count($row) in Global:PHP of views field it returned 1. That also ten times, Means query executed 10 times to retrieve 10 row of data. When I printed the query with dpq($view->build_info['query']); it returned same query 10 times. How can I avoid multiple execution of same query.

  • It executes the query only once, but renders each row individually. If the query returned 10 results, that means 10 rows to render. – AyeshK Jun 6 '14 at 13:20
  • @AyeshK Then how can I get the count before rendering rows – James Jun 7 '14 at 5:38
0

You can list the number of results instead with a snippet of php code in the header:

<?php
  $view = views_get_current_view();
  print $view->total_rows; 
?>

Learned this trick from: https://stackoverflow.com/a/2989197

| improve this answer | |
0

You can also achieve it by taking the number of records in the view. For that you can use the Global: Result summary in that you have @total -- the total records in the set. You can use this. I don't know whether this answer meets your need. Just give a try:)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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