[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

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


Closed Thread
 
LinkBack Thread Tools
Old 07-08-2006, 01:20 AM   #1 (permalink)
Account Closed
 
Join Date: Jul 2006
Posts: 81
104.40 NP$ (Donate)

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
$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.
}
}
?>
electricbeat is offline  
Old 07-08-2006, 01:46 AM   #2 (permalink)
NamePros Regular
 
-PS-'s Avatar
 
Join Date: Jun 2006
Location: Sydney
Posts: 251
5.95 NP$ (Donate)

-PS- will become famous soon enough-PS- will become famous soon enough


Quote:
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");
// 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");
that should do the order thing for you
-PS- is offline  
Old 07-08-2006, 01:57 AM   #3 (permalink)
Account Closed
 
Join Date: Jul 2006
Posts: 81
104.40 NP$ (Donate)

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, 03:30 AM   #4 (permalink)
NamePros Regular
 
-PS-'s Avatar
 
Join Date: Jun 2006
Location: Sydney
Posts: 251
5.95 NP$ (Donate)

-PS- will become famous soon enough-PS- will become famous soon enough


Quote:
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 =)

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, 03:46 AM   #5 (permalink)
Account Closed
 
Join Date: Jul 2006
Posts: 81
104.40 NP$ (Donate)

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, 04:58 AM   #6 (permalink)
NamePros Regular
 
-PS-'s Avatar
 
Join Date: Jun 2006
Location: Sydney
Posts: 251
5.95 NP$ (Donate)

-PS- will become famous soon enough-PS- will become famous soon enough


Quote:
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" . "%" . "'";
whoops, change like = just to like, (remove the = )
-PS- is offline  
Old 07-08-2006, 05:10 AM   #7 (permalink)
Account Closed
 
Join Date: Jul 2006
Posts: 81
104.40 NP$ (Donate)

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:
PHP Code:
$start_var = sub_str($start_var,0,1);
electricbeat is offline  
Old 07-08-2006, 05:18 AM   #8 (permalink)
NamePros Regular
 
-PS-'s Avatar
 
Join Date: Jun 2006
Location: Sydney
Posts: 251
5.95 NP$ (Donate)

-PS- will become famous soon enough-PS- will become famous soon enough


Quote:
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);


remove the underscore (substr) sorry - very tired here burning the candle on both ends so to speak
-PS- is offline  
Old 07-08-2006, 05:22 AM   #9 (permalink)
Account Closed
 
Join Date: Jul 2006
Posts: 81
104.40 NP$ (Donate)

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, 05:24 AM   #10 (permalink)
NamePros Regular
 
Flubber's Avatar
 
Join Date: Jun 2005
Location: UK
Posts: 691
25.95 NP$ (Donate)

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, 05:26 AM   #11 (permalink)
Account Closed
 
Join Date: Jul 2006
Posts: 81
104.40 NP$ (Donate)

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, 05:27 AM   #12 (permalink)
NamePros Regular
 
Flubber's Avatar
 
Join Date: Jun 2005
Location: UK
Posts: 691
25.95 NP$ (Donate)

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, 03:36 PM   #13 (permalink)
NamePros Regular
 
-PS-'s Avatar
 
Join Date: Jun 2006
Location: Sydney
Posts: 251
5.95 NP$ (Donate)

-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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 10:54 PM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

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 73 74 75 76 77 78 79 80 81 82 83 84 85