Created
August 25, 2017 14:37
-
-
Save otnansirk/08e3f823335e67f6dfc122c837a72d26 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$dbh = new PDO('mysql:host=localhost;dbname=[your-database]', "[your-user]", "[your-password]"); | |
//menampilkan data per-page nya $perPage= 3; | |
// get page. mengambil nilai dari get page | |
$page = isset($_GET['page'])? (int)$_GET['page']:1; | |
// start . untuk memulai nilai Limit | |
$start = ($page > 1) ? ($page * $perPage) - $perPage : 0 ; | |
// get users limit. akan mengembalikan data sesuai value $start dengan jumlah $perPage | |
$getLimit = $dbh->query("select * from [your-table] LIMIT $start, $perPage"); | |
// get All., mengambil jumlah row data. | |
$getAll = $dbh->query('select * from [your-table]'); | |
$totalRows = $getAll->rowCount(); | |
// ceil value. hasil dari $totalRows dibagi dengan $perPage lalu akan di bulatkan dengan function ceil() | |
$pages = ceil($totalRows/$perPage); | |
?> | |
//tampilkan data | |
<?php | |
while ($resultLimit = $getLimit->fetch()) { | |
echo $resultLimit['your-row']."<br>"; | |
} | |
?> | |
// links untuk pagination | |
<div class=""> | |
<?php | |
for ($i=1; $i <=$pages ; $i++) { | |
?> | |
<a href="?page=<?= $i?>"><?= $i?></a> | |
<?php | |
} | |
?> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment