项目作者: rendy-ananda

项目描述 :
pagination using php and mysql
高级语言: PHP
项目地址: git://github.com/rendy-ananda/php-mysql-pagination.git
创建时间: 2019-08-21T18:49:28Z
项目社区:https://github.com/rendy-ananda/php-mysql-pagination

开源协议:

下载


php-mysql-pagination

pagination using php and mysql

  • create project folder in your localhost
  • download and copy index.php file into your folder
  • download pagination_db and import to your database
  • just run it’s

*please makesure your db username and password~

``` php
<?php
// connection
$conn = new mysqli(‘localhost’, ‘root’, ‘’, ‘pagination_db’);
// calculation preparation for pagination
$data_per_page = 2; // the amount of data you want to display per page
$amount_of_data = ($conn->query(“SELECT FROM items”))->num_rows; // calculate the amount of data
$number_of_page = ceil($amount_of_data / $data_per_page); // ceil : rounding up value
$active_page = ( isset($_GET[‘page’]) ) ? $_GET[‘page’] : 1; // if else
$initial_data = ($data_per_page
$active_page) - $data_per_page;
// the beginning of the pagination
// go to the previous link
if ( $active_page > 1 ) {
echo ‘< ‘;
}
// pagination
for ($i=1; $i <= $number_of_page; $i++) {
// validation for active page
if ( $i == $active_page ) {
$link = ‘‘.$i.’ ‘;
}
else {
$link = ‘‘.$i.’ ‘;
}
echo $link;
}
// go to the next link
if ( $active_page <> $number_of_page ) {
echo ‘> ‘;
}
// end of pagination
// result data using LIMIT
$result = $conn->query(“SELECT * FROM items LIMIT $initial_data, $data_per_page”);
echo ‘





‘;
while( $x = $result->fetch_object() ) {
echo ‘





‘;
}
echo ‘
Id Item Price
‘.$x->id.’ ‘.$x->item.’ ‘.$x->price.’
‘;
?>