I went through lots of tutorial, and almost all of them were quite long, so I came up with my own code:
$page = $_GET['page'];
$pg_count = $page-1;
if ($page == 1) {
$start = 0;
} else {
$start = $pg_count*15;
}
$limit = $page*15;
$query = 'SELECT * FROM table LIMIT '.$start.', '.$limit.'';
foreach($db->query($query) as $row) {
//outputs
}
$stmt = $db->query('SELECT * FROM table');
$row_count = $stmt->rowCount();
$count = ceil($row_count/15);
for ($i=1; $i<=$count; $i++) {
echo '<a href="?page='.$i.'">'.$i.'</a>';
}
Here i'm displaying 15 results per page.
This small piece of code seems to do the job (new to pdo, sorry if the method of including parameter is wrong).
So basically my question is, is their a much better way to do this?