Jess McKenzie
Jess McKenzie

Reputation: 8385

onClick show the next page

I am creating a page pagination however I am stuck on the for loop. Currently it shows all links from 1 to 99.

How can I make it so that it only shows one number per click as I am wanting to create a "next" button.

Do I have to involve jQuery?

Code:

<?php

for ($i = 1; $i <= 99; ++$i) {

echo '<li><a href="example-' .$i. '">Next</a></li>';
}

?>

Upvotes: 0

Views: 197

Answers (1)

user6763587
user6763587

Reputation:

looks like you just need this:

<?php
if($_GET['page'] >=99){
 exit('ran out of pages');
//no idea what you want here :-)
}

if(empty($_GET['page']) OR !is_int($_GET['page'])){
$_GET['page']=0; //or maybe you want 1, depends on usage
)

$next=$_GET['page']+1;
echo '<li><a href="example.php?page=' .$next. '">Next</a></li>';
?>

Upvotes: 2

Related Questions