Skip to content

Pagination - Example with ADODB

This example demonstrates how to use the Pagination class with results returned as an ADODB RecordSet/ARRAY, including explanations of each available method and an example using a while loop.


📦 Required Import

Add this at the top of your PHP file:

use App\framework\Utils\Pagination;

✅ Full Code (using paginate)

$pagination = new Pagination($_GET);

$pagination_arr = $pagination->paginate($MAIN_QUERY, $PREPARE_ARRAY);
$recordset = $pagination_arr['recordset'];

foreach($recordset as $key => $val){
  // -- CODE GOES IN HERE
}

⚡ Alternative with paginateLight() (better performance)

$pagination = new Pagination($_GET);

$pagination_arr = $pagination->paginateLight($MAIN_QUERY, $PREPARE_ARRAY);
$recordset = $pagination_arr['recordset'];

foreach($recordset as $key => $val){  
  // -- CODE GOES IN HERE
}

🗂️ Method: paginateArray

$pagination = new Pagination($_GET);

$pagination_arr = $pagination->paginateArray($ARRAY);
$recordset = $pagination_arr['recordset'];

foreach($recordset as $key => $val){
  // -- CODE GOES IN HERE
}

🧩 Step-by-Step Explanation

🔹 new Pagination($_GET);

  • Creates a new instance of the Pagination class.
  • $_GET: URL parameters like page, limit.

🔹 $pagination->limit = 10;

  • (Optional) Sets the maximum number of records per page.
  • Example: display 10 records per page.

🔹 $pagination->returnType = 'ADODB';

  • (Optional) Defines the type of data returned by pagination.
  • Available options:
  • 'ADODB': returns an ADODB RecordSet.
  • 'ARRAY': returns results as an array.
  • This must be set before calling paginate() or paginateLight().

🔁 Available Methods

paginate($query, $params = [])

  • Full-featured method.
  • Executes the paginated SQL query.
  • Returns:
  • recordset: records for the current page.
  • pagination_html: HTML with navigation buttons.
  • has_next: whether there is a next page.
  • limit: the current limit used.

paginateLight($query, $params = [])

  • Lightweight and more efficient method (recommended for large datasets).
  • Does not calculate total pages or total records.
  • Returns:
  • recordset: records for the current page.
  • pagination_html: HTML with navigation buttons.
  • has_next: whether there is a next page.
  • limit: the current limit used.

Use paginate() when you need full navigation info (total pages, total records, etc).
Use paginateLight() for better performance when that information is not required.


🔁 while Loop Structure

$rsCounter = 0;
while(!$Recordset->EOF && $rsCounter++ < $pagination_arr['limit']){
    // processing
    $Recordset->MoveNext();
}
  • !$Recordset->EOF: continues until end of RecordSet.
  • $rsCounter++ < $pagination_arr['limit']: ensures only current page records are processed.
  • MoveNext(): moves to the next record in the RecordSet.

Even if the RecordSet fetches one extra record (to detect if there's a next page), this loop limits processing to the current page only.


(Last updated: 2025-06-05)