mahmoud-abdelfadeil/php-pagination

A package to facilitate pagination

1 2022-10-10 15:51 UTC

This package is auto-updated.

Last update: 2024-09-10 20:43:18 UTC


README

A package to facilitate pagination

install

composer require mahmoud-abdelfadeil/php-pagination

Full EX

<?php

use PhpPagination\Pagination;

include 'vendor/autoload.php';
$config_db=[
    "db_host"=>"localhost",
    "db_name"=>"pagination_test",
    "db_user"=>"root",
    "db_password"=>""
];
$pagination = new Pagination($config_db,2);

$users = $pagination->table('users')->column(['*'])->get();
echo "<pre>";
var_dump($users);
?>

<a href="<?php echo $pagination->prevPage() ?>">prev</a><br>

<a href="<?php echo $pagination->nextPage() ?>">next</a><br>

<a href="<?php echo $pagination->firstPage() ?>">first</a><br>

<a href="<?php echo $pagination->lastPage() ?>">last</a><br>

<p>page : <?php echo $pagination->currentPage()  ?> of <?php echo $pagination->countPages()  ?></p>

use

1 - include vendor autoload

include 'vendor/autoload.php';

2 - use class Pagination

use PhpPagination\Pagination;

3 - database config (array keys static)

$config_db=[
    "db_host"=>"localhost",
    "db_name"=>"pagination_test",
    "db_user"=>"root",
    "db_password"=>""
];

4 - instans object Pagination (param 1 , param 2)

// param 1 (required)=>array config database
// param 2 (optional)=>int count items [default 20]

$count_items=10; //  optional (default 20 items in 1 page)
$pagination = new Pagination($config_db , $count_item);

5 - EX

$users = $pagination->table('users')->column(['*'])->get();
// tabel (table name)
// column (select column in table ) 
// column array | string 
// ex string
$users = $pagination->table('users')->column('*')->get();
$users = $pagination->table('users')->column('name , email')->get();

// ex array 
$users = $pagination->table('users')->column(['*'])->get();
$users = $pagination->table('users')->column(['name' , 'email'])->get();

5 - Helper function :

prevPage() previous page

nextPage() next page

firstPage() first page

lastPage() last page

currentPage() current page

countPages() count pages

<a href="<?php echo $pagination->prevPage() ?>">prev</a><br>

<a href="<?php echo $pagination->nextPage() ?>">next</a><br>

<a href="<?php echo $pagination->firstPage() ?>">first</a><br>

<a href="<?php echo $pagination->lastPage() ?>">last</a><br>

<p>page : <?php echo $pagination->currentPage()  ?> of <?php echo $pagination->countPages()  ?> </p> // output page : 49 of 53