Pagination page

Post here is you are having problems with any of the tutorials.
Post Reply
User avatar
louiegiezer
Posts: 57
Joined: Fri Oct 21, 2011 11:31 am
Contact:

Pagination page

Post by louiegiezer »

Hey Guys!

I'm planning to implement the pagination tutorial in my website made by Mr.Jacek so in this tutorial instead of the next page is a number i want to change it in Next and Previous is this possible?
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Pagination page

Post by jacek »

Yes.
Image
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: Pagination page

Post by Temor »

Yes. Very easily even.

If you're having troubles figuring it out, let me know :)
User avatar
louiegiezer
Posts: 57
Joined: Fri Oct 21, 2011 11:31 am
Contact:

Re: Pagination page

Post by louiegiezer »

thanks. Lets begin :lol:
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: Pagination page

Post by Temor »

show us what you have so far :)
User avatar
louiegiezer
Posts: 57
Joined: Fri Oct 21, 2011 11:31 am
Contact:

Re: Pagination page

Post by louiegiezer »

here's the code


user_list.php
<?php

include('core/init.inc.php');

$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
?>

<html>
	<head>
		<title>Pagination Test</title>
	</head>
	<body>
		<div>	
			<?php
				foreach (fetch_users($page, 5) as $user){
					echo "<p>{$user}</p>";
				}
				
			$total_pages = ceil(fetch_total_users() / 5);
			
			for ($i = 1; $i <= $total_pages; ++$i){
				echo " <a href=\"?page={$i}\">{$i}</a> ";
			}
			
			?>
		</div>
	</body>
</html>


user.inc.php
<?php

function fetch_users($page, $per_page){
	$start		 = (int)($page -1) * $per_page;
	$per_page	 = (int)$per_page;
	
	$query = mysql_query("SELECT `user_name` FROM `tester` LIMIT {$start}, {$per_page}");

	while (($row = mysql_fetch_assoc($query)) !== false){
		$users[] = $row['user_name'];
	}
	return $users;
}

function fetch_total_users(){
	$result = mysql_query('SELECT COUNT(`user_id`)FROM `tester`');
	
	return mysql_result($result, 0);
}
?>
so how to make this prev and next
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Pagination page

Post by jacek »

Well the next page is current_page + 1 so
echo '<a href="?page=', ($page + 1), '">Next</a>';
should be a good place to start.
Image
User avatar
louiegiezer
Posts: 57
Joined: Fri Oct 21, 2011 11:31 am
Contact:

Re: Pagination page

Post by louiegiezer »

:cry: well its better if you give the exact code in prev and next..
bowersbros
Posts: 534
Joined: Thu May 05, 2011 8:19 pm

Re: Pagination page

Post by bowersbros »

Jacek has given you exactly what you need to figure it out for yourself.

You wont learn if he provides code for you, and frankly. Why should he do it for you? Its your website; Not his.

The code that Jacek gave will work, however you will need to adapt it slightly and enhance it abit more. Just give it a try.
I don't like to brag, but I wasn't circumcised. I was circumnavigated. ;)

Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
Post Reply