PHP pagination / ordering help etc.

Spacemail by SpaceshipSpacemail by Spaceship
SpaceshipSpaceship
SpaceshipSpaceship
Watch

electricbeat

Account Closed
Impact
0
I have a browse.php file that shows all the user members. I need it so I have a-b-c-d-e- etc listed at the top and also show 10 users on each page aswell, so basically like the vbulletin memberlist.php file.

I need this basically http://195.137.45.236/memberlist.php but just the users alphabetically ordered, if anyone could help it would be great and I'd give all of my NP if I have any.

PHP:
<?php
ob_start();
include("config.php");
if (!$_GET[user]){
if(!isset($_GET['page'])){
$page = 1;
} else {
$page = $_GET['page'];
}
$max_results = "20"; // Change to how many member you would like to display per page
$from = (($page * $max_results) - $max_results);
$getuser = mysql_query("SELECT * FROM users ORDER BY id ASC LIMIT $from, $max_results");
while ($user = mysql_fetch_array($getuser)){
// gets all the users information.
echo ("<a href=\"browse.php?user=$user[username]\">$user[username]</a><br />\n");
// links to a page to view the user's profile.
}
echo "Go to page: ";
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM users"),0);
$total_pages = ceil($total_results / $max_results);
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "$i ";
} else {
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\" title=\"Go to page $i\">$i</a> ";
}
}
} else {
$getuser = mysql_query("SELECT * FROM users WHERE username = '$_GET[user]'");
$usernum = mysql_num_rows($getuser);
if ($usernum == 0){
echo ("User Not Found");
} else {
$profile = mysql_fetch_array($getuser);
echo ("Username: <i>$profile[username]</i><br />
Location: <i>$profile[location]</i><br />
Email: <i>$profile[email]</i><br><br>

<b>Music Interests</b><br />
1. $profile[artist1] - <i>$profile[song1]</i><br />
2. $profile[artist2] - <i>$profile[song2]</i><br />
3. $profile[artist3] - <i>$profile[song3]</i><br />
4. $profile[artist4] - <i>$profile[song4]</i><br />
5. $profile[artist5] - <i>$profile[song5]</i><br />
6. $profile[artist6] - <i>$profile[song6]</i><br />
7. $profile[artist7] - <i>$profile[song7]</i><br />
8. $profile[artist8] - <i>$profile[song8]</i><br />
9. $profile[artist9] - <i>$profile[song9]</i><br />
10. $profile[artist10] - <i>$profile[song10]</i><br />
");
// in the above code, we display the user's information.
}
}
?>
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
electricbeat said:
I have a browse.php file that shows all the user members. I need it so I have a-b-c-d-e- etc listed at the top and also show 10 users on each page aswell, so basically like the vbulletin memberlist.php file.

I need this basically http://195.137.45.236/memberlist.php but just the users alphabetically ordered, if anyone could help it would be great and I'd give all of my NP if I have any.

PHP:
<?php
ob_start();
include("config.php");
if (!$_GET[user]){
if(!isset($_GET['page'])){
$page = 1;
} else {
$page = $_GET['page'];
}
$max_results = "20"; // Change to how many member you would like to display per page
$from = (($page * $max_results) - $max_results);
$getuser = mysql_query("SELECT * FROM users ORDER BY id ASC LIMIT $from, $max_results");
while ($user = mysql_fetch_array($getuser)){
// gets all the users information.
echo ("<a href=\"browse.php?user=$user[username]\">$user[username]</a><br />\n");
// links to a page to view the user's profile.
}
echo "Go to page: ";
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM users"),0);
$total_pages = ceil($total_results / $max_results);
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "$i ";
} else {
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\" title=\"Go to page $i\">$i</a> ";
}
}
} else {
$getuser = mysql_query("SELECT * FROM users WHERE username = '$_GET[user]'");
$usernum = mysql_num_rows($getuser);
if ($usernum == 0){
echo ("User Not Found");
} else {
$profile = mysql_fetch_array($getuser);
echo ("Username: <i>$profile[username]</i><br />
Location: <i>$profile[location]</i><br />
Email: <i>$profile[email]</i><br><br>

<b>Music Interests</b><br />
1. $profile[artist1] - <i>$profile[song1]</i><br />
2. $profile[artist2] - <i>$profile[song2]</i><br />
3. $profile[artist3] - <i>$profile[song3]</i><br />
4. $profile[artist4] - <i>$profile[song4]</i><br />
5. $profile[artist5] - <i>$profile[song5]</i><br />
6. $profile[artist6] - <i>$profile[song6]</i><br />
7. $profile[artist7] - <i>$profile[song7]</i><br />
8. $profile[artist8] - <i>$profile[song8]</i><br />
9. $profile[artist9] - <i>$profile[song9]</i><br />
10. $profile[artist10] - <i>$profile[song10]</i><br />
");
// in the above code, we display the user's information.
}
}
?>


ok going to take a guess..

you need to change
PHP:
$getuser = mysql_query("SELECT * FROM users ORDER BY id ASC LIMIT $from, $max_results");

to
PHP:
$getuser = mysql_query("SELECT * FROM users ORDER BY username ASC LIMIT $from, $max_results");

that should do the order thing for you
 
0
Close
That lists them in order, thank you.

Now I need someone to help me do this.

A-B-C-D-E-F-G-H-I-J-K-L-M-N-O-P-Q-R-S-T-U-V-W-X-Y-Z

Clicking one of them will show all users that have A at the start of their name.
 
0
Close
electricbeat said:
That lists them in order, thank you.

Now I need someone to help me do this.

A-B-C-D-E-F-G-H-I-J-K-L-M-N-O-P-Q-R-S-T-U-V-W-X-Y-Z

Clicking one of them will show all users that have A at the start of their name.

ok, that one is pretty easy as well. and making it safe as well =)

ok, on the links (ie A-B-C) add &start=(letter) ie &start=a &start=b

in your script
just before the $from add in
PHP:
$start_var = $_GET['start'];
$start_var = sub_str($start_var,0,1);
if(preg_match("([a-zA-Z])",$start_var))
{
$where_clause = "where username like ='$start_var" . "%" . "'";
}
else
$where_clause = "";

and change
PHP:
$getuser = mysql_query("SELECT * FROM users ORDER BY id ASC LIMIT $from, $max_results");
to
PHP:
$getuser = mysql_query("SELECT * FROM users $where_clause ORDER BY id ASC LIMIT $from, $max_results");

*warning : i haven't tested the code, so there's probly some stupid typo or 3,393 in there !
 
0
Close
I cant seem to get it too work, if anyone can assemble the code with the coded posted by powerspike i'd be greatful.
 
0
Close
electricbeat said:
I cant seem to get it too work, if anyone can assemble the code with the coded posted by powerspike i'd be greatful.

PHP:
$where_clause = "where username like ='$start_var" . "%" . "'";

whoops, change like = just to like, (remove the = )
 
0
Close
Fatal error: Call to undefined function: sub_str() in /home/ryan/public_html/browse.php on line 59

Line 59:
PHP:
$start_var = sub_str($start_var,0,1);
 
0
Close
electricbeat said:
Fatal error: Call to undefined function: sub_str() in /home/ryan/public_html/browse.php on line 59

Line 59:
PHP:
$start_var = sub_str($start_var,0,1);



remove the underscore (substr) sorry - very tired here burning the candle on both ends so to speak
 
0
Close
OK - no errors now! thx!!

How would I link to A - B etc.

My script is on a page called browse.php

so I guess I would have to link to browse.php?something=A or something, any help?
 
0
Close
Im guessing it would be browse.php?start=a
And so on.

Flubb.
 
0
Close
Yeah, just done it before you posted lol.

I'll send power my NP and send Flubber some when I earn/buy some, thank you guys!
 
0
Close
No problem, nor any need to send me NP$.

Happy to help, :)

Flubb.
 
0
Close
sounds like everything is working good good !
 
0
Close
DomainEasy: white label portfolios are live. Enable yours.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back