does anyone have a good pagination video i can watch, i try to find one but no one of them works on my browser, it keeps saying: This webpage has a redirect loop.
eksampel:
include "connect.php";
$per_page = 5;
$pages_query = mysql_query("SELECT COUNT(id) FROM bruker") or die(mysql_error());
$pages = ceil(mysql_result($pages_query, 0) / $per_page);
if(!isset($_GET['pages'])) {
header("location: pagination.php?page=1");
} else {
$page = $_GET['page'];
}
$start = (($page - 1) * $per_page);
$bruker = mysql_query("SELECT * FROM bruker LIMIT $start, $per_page");
while($row = mysql_fetch_assoc($bruker)) {
$bruker = $row['bruker'];
echo $bruker . "<br />";
}
pagination
Moderator: General Moderators
Re: pagination
etsted wrote:does anyone have a good pagination video i can watch, i try to find one but no one of them works on my browser, it keeps saying: This webpage has a redirect loop.
Code: Select all
if(!isset($_GET['pages'])) {
header("location: pagination.php?page=1");Rather than redirecting, why don't you just set $page to 1 if it isn't set?
Re: pagination
Keep in mind that a header() will not stop your script. It will keep running. So with what you have now, if the page isn't set then it'll add that redirect header yeah, but it'll then continue on to try to execute the SELECT query and all that. But with $page not set, $start = (null - 1) * 5 = -5 and you end up with an invalid
And +1 to what Celauran said: don't bother with a redirect and just assume the default $page = 1. And while you're in there you should validate the number - don't want people putting ?page=-1 or ?page=notanumber to screw up your code.
Code: Select all
SELECT * FROM bruker LIMIT -5, 5Re: pagination
no video, but you can check this simple pagination scripts
http://www.php-guru.in/2014/pagination- ... page-goto/
http://www.php-guru.in/2014/pagination-php-mysql/
http://www.php-guru.in/2014/pagination- ... page-goto/
http://www.php-guru.in/2014/pagination-php-mysql/