NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page PHP pagination / ordering help etc.

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 07-08-2006, 02:20 AM THREAD STARTER               #1 (permalink)
Account Closed
Join Date: Jul 2006
Posts: 81
electricbeat is an unknown quantity at this point
 



PHP pagination / ordering help etc.


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 Code:
<?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
????: NamePros.com http://www.namepros.com/programming/214681-php-pagination-ordering-help-etc.html
$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 />
????: NamePros.com http://www.namepros.com/showthread.php?t=214681
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.
}
}
?>
electricbeat is offline  
Old 07-08-2006, 02:46 AM   #2 (permalink)
NamePros Regular
 
-PS-'s Avatar
Join Date: Jun 2006
Location: Sydney
Posts: 251
-PS- will become famous soon enough-PS- will become famous soon enough
 



Originally Posted by electricbeat
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 Code:
<?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");
????: NamePros.com http://www.namepros.com/showthread.php?t=214681
// 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 Code:
$getuser mysql_query("SELECT * FROM users ORDER BY id ASC LIMIT $from$max_results"); 
to
PHP Code:
$getuser mysql_query("SELECT * FROM users ORDER BY username ASC LIMIT $from$max_results"); 
????: NamePros.com http://www.namepros.com/showthread.php?t=214681
that should do the order thing for you
-PS- is offline  
Old 07-08-2006, 02:57 AM THREAD STARTER               #3 (permalink)
Account Closed
Join Date: Jul 2006
Posts: 81
electricbeat is an unknown quantity at this point
 



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.
electricbeat is offline  
Old 07-08-2006, 04:30 AM   #4 (permalink)
NamePros Regular
 
-PS-'s Avatar
Join Date: Jun 2006
Location: Sydney
Posts: 251
-PS- will become famous soon enough-PS- will become famous soon enough
 



Originally Posted by electricbeat
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 =)
????: NamePros.com http://www.namepros.com/showthread.php?t=214681
????: NamePros.com http://www.namepros.com/showthread.php?t=214681

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 Code:
$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 Code:
$getuser mysql_query("SELECT * FROM users ORDER BY id ASC LIMIT $from$max_results"); 
to
PHP Code:
$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 !
-PS- is offline  
Old 07-08-2006, 04:46 AM THREAD STARTER               #5 (permalink)
Account Closed
Join Date: Jul 2006
Posts: 81
electricbeat is an unknown quantity at this point
 



I cant seem to get it too work, if anyone can assemble the code with the coded posted by powerspike i'd be greatful.
electricbeat is offline  
Old 07-08-2006, 05:58 AM   #6 (permalink)
NamePros Regular
 
-PS-'s Avatar
Join Date: Jun 2006
Location: Sydney
Posts: 251
-PS- will become famous soon enough-PS- will become famous soon enough
 



Originally Posted by electricbeat
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 Code:
$where_clause "where username like ='$start_var"%" "'"
????: NamePros.com http://www.namepros.com/showthread.php?t=214681
whoops, change like = just to like, (remove the = )
-PS- is offline  
Old 07-08-2006, 06:10 AM THREAD STARTER               #7 (permalink)
Account Closed
Join Date: Jul 2006
Posts: 81
electricbeat is an unknown quantity at this point
 



Fatal error: Call to undefined function: sub_str() in /home/ryan/public_html/browse.php on line 59

Line 59:
????: NamePros.com http://www.namepros.com/showthread.php?t=214681
PHP Code:
$start_var sub_str($start_var,0,1); 
electricbeat is offline  
Old 07-08-2006, 06:18 AM   #8 (permalink)
NamePros Regular
 
-PS-'s Avatar
Join Date: Jun 2006
Location: Sydney
Posts: 251
-PS- will become famous soon enough-PS- will become famous soon enough
 



Originally Posted by electricbeat
Fatal error: Call to undefined function: sub_str() in /home/ryan/public_html/browse.php on line 59

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


????: NamePros.com http://www.namepros.com/showthread.php?t=214681
remove the underscore (substr) sorry - very tired here burning the candle on both ends so to speak
-PS- is offline  
Old 07-08-2006, 06:22 AM THREAD STARTER               #9 (permalink)
Account Closed
Join Date: Jul 2006
Posts: 81
electricbeat is an unknown quantity at this point
 



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?
electricbeat is offline  
Old 07-08-2006, 06:24 AM   #10 (permalink)
NamePros Regular
 
Flubber's Avatar
Join Date: Jun 2005
Location: UK
Posts: 688
Flubber is a splendid one to beholdFlubber is a splendid one to beholdFlubber is a splendid one to beholdFlubber is a splendid one to beholdFlubber is a splendid one to beholdFlubber is a splendid one to beholdFlubber is a splendid one to beholdFlubber is a splendid one to behold
 


Baby Health
Im guessing it would be browse.php?start=a
And so on.

Flubb.
Flubber is offline  
Old 07-08-2006, 06:26 AM THREAD STARTER               #11 (permalink)
Account Closed
Join Date: Jul 2006
Posts: 81
electricbeat is an unknown quantity at this point
 



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!
electricbeat is offline  
Old 07-08-2006, 06:27 AM   #12 (permalink)
NamePros Regular
 
Flubber's Avatar
Join Date: Jun 2005
Location: UK
Posts: 688
Flubber is a splendid one to beholdFlubber is a splendid one to beholdFlubber is a splendid one to beholdFlubber is a splendid one to beholdFlubber is a splendid one to beholdFlubber is a splendid one to beholdFlubber is a splendid one to beholdFlubber is a splendid one to behold
 


Baby Health
No problem, nor any need to send me NP$.

Happy to help,

Flubb.
Flubber is offline  
Old 07-08-2006, 04:36 PM   #13 (permalink)
NamePros Regular
 
-PS-'s Avatar
Join Date: Jun 2006
Location: Sydney
Posts: 251
-PS- will become famous soon enough-PS- will become famous soon enough
 



sounds like everything is working good good !
-PS- is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 07:07 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger