Hi all,

I have a site, where everything is on the index.php page - and then I include files when needed. Im not sure if this matters, but now you know..the page I am trying to create pagination on, is in an included file.

So the page/url i am working on for pagination is: index.php?billeder

This is happening, and not happening:

The $page is set to start at value = 1, so when you first get to the page, you see the first five results, so that part works fine.

BUT: When one of the links created in the pagi. script, is clicked: I do get
the URL = index.php?billeder=1 - But then the page is left blank, and no data is being pulled from the database.

Basically it works great until you use the links..which is build wrong or?

Can some pagination shark see what I am doing wrong just below?

This is what i have:

$pr_page = 5;
$sql = mysqli_query($connection, "SELECT user_id FROM images");
$rows = mysqli_num_rows($sql);
$pages= ceil($rows / $pr_page);

//Cast $_GET as an int, that can be used for pagination, and create default of 1 if not set:
$page = (isset($_GET['billeder']) && (int)$_GET['billeder'] > 0) ? (int)$_GET['billeder'] : 1;

$start = ($page - 1) * $pr_page; // SQL starter på 0 værdi //

$sql = mysqli_query($connection, "SELECT * FROM images LIMIT $start, $pr_page");

// Create pagination links here:
for($x = 1; $x <= $pages; $x++) 
echo $x == $page ? '<strong><a href="index.php?billeder='.$x.'">'.$x.'</a></strong> ' : '<a href="index.php?billeder='.$x.'">'.$x.'</a> ';

// And then I echo out the info i want to be paginated, not showing it, as it is not important regarding my pagination probs..:
while ($image = mysqli_fetch_array($sql))
echo 'data data data...............';

Regards, Klemme

Arh it works now, it was because in my index page when i decide which page is set, i only allowed index.php?billeder and not index.php?billeder=value..

Its a small pagination script which I think does the job, but doesnt display first or last links, just pretty basic..well it works now anyways.


Cool. That's good to hear that you've tried fixing the problem/s with your code. That'd be great if you just mark the thread as solved.


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.