how to make next and previous page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
unix77
Forum Newbie
Posts: 7
Joined: Tue Jun 07, 2005 6:13 am
Location: south korea

how to make next and previous page

Post by unix77 »

Hi everybody

I tried to print my array so I can have many page from my array. I want the user can see next page and previous page by clicking linking page.I believe that this is logic problem instead of PHP problem.

Code: Select all

<?php
	$page[30];
	for($i=0;$i<30;$i++){
		$page[$i] = $i;
	}

	$k=0;
	$k = $_GET['k'];

	echo "<br><br><br><br>";

	$y=$k*5;
	$z=$y+5;
	for($i=$y;$i<$z;$i++){
			echo $page[$i];
			echo "<br>";
	}

	echo "<br>";
	$x = (count($page)/5)-1;


	if($k<$x){
	$k++;
	$address="http://localhost/testpage.php?k=$k";
	echo "<a href=$address>";
	echo "next\n\n\n";
	echo "</a>";
	echo "<<<<< >>>>>>";
	}		  

	if($k>=$x||$k>1){
		$w = $k-2;
		$address="http://localhost/testpage.php?k=$w";
		echo "<a href=$address>";
		echo "\n\n\nprevious";
		echo "</a>";
	}


?>
My problem is my page cannot move in final page-1

Thanks
User avatar
harrison
Forum Commoner
Posts: 30
Joined: Thu Jun 09, 2005 12:23 am

Post by harrison »

This topic is answered many times in this forum. Try searching for keywords such as 'pagination'.
Post Reply