Members Page Pagination


Okay everyone! this was requested on the forums and such so i thought i would throw it together ^_^

So first and really only thing you have to do is open your members.php and add the things i have added below.

PHP Code
  1. <?php
  2. session_start(); //allows session
  3. include "config.php";
  4. if(!$_GET[page]){ //check if there is a page number
  5. $page = 1; //if there isn't the page is 1
  6. }else{
  7. $page = $_GET[page]; //if there is a page then it is what the page is
  8. } //end page check
  9. $max_results = 10; //members per page
  10. $result_math = (($page * $max_results) - $max_results); //work out results to show
  11. echo "<center>";
  12. if(isset($_GET['user'])){ //if there trying to view a profile
  13. //gets the user name and makes it safe
  14. $username = addslashes($_GET[user]);
  15. //querys the db to find the username
  16. $getuser = mysql_query("SELECT * FROM `members` WHERE `username` = '$username'");
  17. //checks see if the username exists in the db
  18. $usernum = mysql_num_rows($getuser);
  19. //if it don't exist
  20. if ($usernum == 0)
  21.  
  22. {
  23. //don't exist
  24.  
  25. echo ("User Not Found");
  26.  
  27. }
  28. //if it does exist then show there profile
  29. else
  30. {
  31. $user = mysql_fetch_array($getuser);
  32. echo "<fieldset style='width: 350'>
  33. <b>$user[username]'s Profile</b><br><br>
  34. Email: $user[email]<br>
  35. Location: $user[location]<br>
  36. Sex: $user[sex]<br>
  37. Age: $user[age]
  38. </fieldset>";
  39.  
  40. }
  41. }
  42. else
  43. {
  44. //gets all the members from the database
  45. $getusers = mysql_query("SELECT * FROM `members` ORDER BY `id` DESC LIMIT $result_math, $max_results") or die(mysql_error()); //get users limiting by result math and max results
  46. $total_members = mysql_num_rows($getusers); //count members
  47. $total_pages = ceil($total_members / $max_results); //make total pages
  48. //loops there name out
  49. while ($user = mysql_fetch_array($getusers))
  50. {
  51. echo "<a href='members.php?user=$user[username]'>$user[username]</a><br>";
  52. }
  53. if($page > 1){ //if the page number is bigger than 1
  54. $prev = ($page - 1); //previous is page minus 1
  55. echo '<a href="members.php?page=$prev" title="Go To Page: $prev">« Previous</a>'; //give the previous link
  56. } //end
  57. die('Copy And Paster!'); //you gotta remove this..
  58. for($i = 1;$i<=$total_pages;$i++){ //start making more pages :)
  59. if($page == $i){ //if the current page is the same as the number than
  60. echo '<b>$i</b> '; //dont give it as a link
  61. }else{ //or...
  62. echo '<a href="members.php?page=$i" title="Go To Page: $i">$i</a> '; //give as link :)
  63. }
  64. }
  65. if($page < $total_pages){ //if the page is less than total
  66. $next = ($page + 1); //add one to page
  67. echo '<a href="members.php?page=$next" title="Go Ro Page: $next">Next »</a>'; //give next link
  68. } //end
  69. }
  70. echo "<center>";
  71. ?>


Read through it carefully :)
ShadowMage's Avatar
Author:
Views:
3,949
Rating:
Posted on Tuesday 27th January 2009 at 07:37 PM
medz
medz's Avatar
It dosent show the amount of members I want and it dosent give me the link for next and the link for previous is /members.php?page=$prev

And im not using members.php so I didnt just copy and paste it though that mite be where the error came from. Im using it on the pet highsocres pages. >_>
Posted on Friday 8th August 2008 at 08:35 PM
UrbanTwitch
UrbanTwitch's Avatar
I got &=1 in the links
Posted on Friday 8th August 2008 at 07:14 PM
JakkyD
JakkyD's Avatar
Lol, you have to remove this line near the bottom:

die('Copy And Paster!'); //you gotta remove this..
Posted on Thursday 7th August 2008 at 03:29 AM
UrbanTwitch
UrbanTwitch's Avatar
It shows the first 10 members then at the bottom it says:

Copy And Paster!

.... help?
Posted on Monday 28th July 2008 at 12:35 AM
UrbanTwitch
UrbanTwitch's Avatar
Doesn't work for me :(
Posted on Wednesday 16th July 2008 at 11:27 AM
Dava
Dava's Avatar
it does nathan it doesnt give you page numbers or next/previous links
Posted on Sunday 13th April 2008 at 05:28 AM
Nathan
Nathan's Avatar
doesnt give you the link to there profile
Posted on Saturday 22nd December 2007 at 07:49 PM
Diablosblizz
Diablosblizz's Avatar
Alright. :P
Posted on Saturday 22nd December 2007 at 01:25 PM
new2old
new2old's Avatar
no need fixed it :)
Posted on Thursday 20th December 2007 at 03:05 AM
Diablosblizz
Diablosblizz's Avatar
New2Old - PM me for a working code, I can't post it here.