1 Reply Latest reply on Apr 19, 2011 10:16 PM by DanielMare

    CWP:  Get number of results

    DanielMare

      Title

      CWP:  Get number of results

      Your post

      I need to get number of records in order to create page links, i.e. Page 1, Page 2, Page 3 - i.e. if 10 records per page, and 30 records total, there needs to be 3 page links.

      My current solution is:

      $result = $request->execute();
      $records = $result->getRecords();
      $num_records = count($records);

      Then to actually show content for current page:

      $request->setRange(blabla);
      $result = $request->execute(); // <-- again

      etc, etc.

      This works, but issue I have is it is very slow.  It seems quite inefficient to execute a result and get records for the simple purpose of counting them.

      Is there a better way?     e.g. in mysql, I used: "SELECT COUNT(*) FROM table"

        • 1. Re: CWP:  Get number of results
          DanielMare

          For anyone else requiring a solution to this - this is one solution:

          Create a new Calculation field in the table: Get(FoundCount) <- this will actually ignore the setRange, which is good!

          $request->setRange(blabla);
          $result = $request->execute();
          $result = $request->execute();
          $records = $result->getRecords();

          Put the page links script inside the foreach($records as $record) loop using a flag variable to ensure the page links are only printed on the first run of the loop!