Forgot Password / Register
Site Statistics
Total Members: 520
Total Tutorials: 242
Newsest User: 8884244477
Todays Unique Hits: 284
0 Users 2 Guests Online

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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
session_start
(); //allows session
include "config.php";
if(!
$_GET[page]){ //check if there is a page number
$page 1//if there isn't the page is 1
}else{
$page $_GET[page]; //if there is a page then it is what the page is
//end page check
$max_results 10//members per page
$result_math = (($page $max_results) - $max_results); //work out results to show
echo "<center>";
if(isset(
$_GET['user'])){ //if there trying to view a profile
//gets the user name and makes it safe
$username addslashes($_GET[user]);
//querys the db to find the username
$getuser mysql_query("SELECT * FROM `members` WHERE `username` = '$username'");
//checks see if the username exists in the db 
$usernum mysql_num_rows($getuser);
//if it don't exist 
if ($usernum == 0


//don't exist

echo ("User Not Found"); 


//if it does exist then show there profile
else
{
$user mysql_fetch_array($getuser); 
echo 
"<fieldset style='width: 350'>
<b>
$user[username]'s Profile</b><br><br>
Email: 
$user[email]<br>
Location: 
$user[location]<br>
Sex: 
$user[sex]<br>
Age: 
$user[age]
</fieldset>"
;

}
}
else
{
//gets all the members from the database
$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
$total_members mysql_num_rows($getusers); //count members
$total_pages ceil($total_members $max_results); //make total pages
//loops there name out
while ($user mysql_fetch_array($getusers)) 

echo 
"<a href='members.php?user=$user[username]'>$user[username]</a><br>"
}
if(
$page 1){ //if the page number is bigger than 1
$prev = ($page 1); //previous is page minus 1
echo '<a href="members.php?page=$prev" title="Go To Page: $prev">« Previous</a>'//give the previous link
//end
die('Copy And Paster!'); //you gotta remove this..
for($i 1;$i<=$total_pages;$i++){ //start making more pages :)
if($page == $i){ //if the current page is the same as the number than
echo '<b>$i</b> '//dont give it as a link
}else{ //or...
echo '<a href="members.php?page=$i" title="Go To Page: $i">$i</a> '//give as link :)
}
}
if(
$page $total_pages){ //if the page is less than total
$next = ($page 1); //add one to page
echo '<a href="members.php?page=$next" title="Go Ro Page: $next">Next »</a>'//give next link
//end
}
echo 
"<center>";
?>


Read through it carefully :)
ShadowMage
Author:
Views:
2993
Rating:
Posted on Tuesday 27th January 2009 at 07:37 PM
medz
medz
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
I got &=1 in the links
Posted on Friday 8th August 2008 at 07:14 PM
JakkyD
JakkyD
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
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
Doesn't work for me :(
Posted on Wednesday 16th July 2008 at 11:27 AM
Dava
Dava
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
doesnt give you the link to there profile
Posted on Saturday 22nd December 2007 at 07:49 PM
Diablosblizz
Diablosblizz
Alright. :P
Posted on Saturday 22nd December 2007 at 01:25 PM
new2old
new2old
no need fixed it :)
Posted on Thursday 20th December 2007 at 03:05 AM
Diablosblizz
Diablosblizz
New2Old - PM me for a working code, I can't post it here.