Skip to content

thielicious/xPager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

xPager

An API for pagination



INTRODUCTION

xPager is an API to paginate data which is fully optimizable.


SETUP INFORMATION

Use your CLI and enter the following to clone:
git clone https://github.com/thielicious/xPager.git


USAGE

Get the namespace:
(Feel free to change or remove the namespace)

use Thielicious\APIs\xPager as xPager;

Create an object:

$paginator = new xPager\xPager("localhost", "root", "", "news_blog");

Style your control bar:

$paginator->setControl(" |< ", " > ", " < ", " >| "); // optional
$paginator->setLnkStyle("active", "inactive");        // required
$paginator->setDivider("|", "|");                     // optional

Fetch records from a database table:

$paginator->SQLRequest("
  SELECT * FROM `TableName`
");

Set the page count:

$paginator->paging(3, "page");
$paginator->paginate();

Display the records: (example)

foreach ($paginator->displayRecords as $rec) {
  echo $rec->data;
}

METHODS

xPager::__construct(string $host, string $username, string $password, string $db = NULL) (required)
Connects to the specified database.

  • $host Defines the server (e.g. localhost)
  • $username Defines the username for your database
  • $password Password for the database
  • $db (optional) In case if it's not yet defined, choose your database name

xPager::setControl(string $first, string $next, string $previous, string $last) (optional)
This method will show the content being shown to control xPager. It can be any character, image or links but usually arrows.

  • $first Shows the first page (default: "First")
  • $next Will render the next available page (default: "Next")
  • $previous Goes to the previous page by 1 step (default: "Back")
  • $last Renders the last page (default: "Last")

xPager::setLnkStyle(string $active, string $inactive) (required)
Creates a link for each page and apply the style using classes defined in CSS.

  • $active Styles the active page number
  • $inactive Styles the other page numbers

xPager::setDivider(string $ctrl, string $pg) (optional)
This will join a separator between the controllers and page numbers.

  • $ctrl Separator for the controllers (default: "|")
  • $pg Separator for the pages (default: "|")

xPager::SQLRequest(string $sql) (required)
Look up data from a table.

  • $sql Query requests in SQL only

xPager::getCount() (optional)
Displays the total amount of data.


xPager::paging(int $limit, string $pagename = NULL) (required)
Defines the amount of data being shown on each page.

  • $limit Data limit for each page
  • $pagename (optional) Defines the page name as a key value for a GET request

xPager::paginate() (optional)
This will calculate and render the pages and the control bar using the defined settings above. This method should always be placed after all other methods explained above.


ARRAY

xPager::displayRecords (required)
This is an array containing the SQL data for each page. This should be placed at the very end.



🆕 A Demo has been added.



If you encounter any bugs, feel free to open up an issue, thank you.

thielicious.github.io

Releases

No releases published

Packages

No packages published

Languages