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?
Pagination page
- louiegiezer
- Posts: 57
- Joined: Fri Oct 21, 2011 11:31 am
- Contact:
Re: Pagination page
Yes. Very easily even.
If you're having troubles figuring it out, let me know
If you're having troubles figuring it out, let me know
- louiegiezer
- Posts: 57
- Joined: Fri Oct 21, 2011 11:31 am
- Contact:
Re: Pagination page
thanks. Lets begin
Re: Pagination page
show us what you have so far
- louiegiezer
- Posts: 57
- Joined: Fri Oct 21, 2011 11:31 am
- Contact:
Re: Pagination page
here's the code
user_list.php
user.inc.php
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
Re: Pagination page
Well the next page is current_page + 1 so
echo '<a href="?page=', ($page + 1), '">Next</a>';should be a good place to start.
- louiegiezer
- Posts: 57
- Joined: Fri Oct 21, 2011 11:31 am
- Contact:
Re: Pagination page
well its better if you give the exact code in prev and next..
-
- Posts: 534
- Joined: Thu May 05, 2011 8:19 pm
Re: Pagination page
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.
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
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