SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
-
Mar 11, 2009, 09:02 #1
- Join Date
- Dec 2005
- Posts
- 964
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Loop limit 7 with specific userid in middle?!?
Confused!? What I want is to print a user list but only 7 users... 3 above the current user and 3 below.
Lets say that the user is #49. I would then like to get a print like this:
#46
#47
#48
#49
#50
#51
#52
Is that possible, and if yes... How?!
PHP Code:$query="SELECT * FROM users ORDER BY uid";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)){
echo ''.$row['name'].'<br>';
}
-
Mar 11, 2009, 09:11 #2
- Join Date
- Aug 2007
- Posts
- 566
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
PHP Code:$pivotUid=49;
$min=$pivotUid-3;
$max=$pivotUid+3;
$sql="select * from users where uid between $min and $max order by uid";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)){
//do something
}
-
Mar 11, 2009, 09:19 #3
- Join Date
- Dec 2005
- Posts
- 964
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks... Just what I was looking 4
-
Mar 11, 2009, 10:23 #4
- Join Date
- Jul 2002
- Location
- Toronto, Canada
- Posts
- 39,347
- Mentioned
- 63 Post(s)
- Tagged
- 3 Thread(s)
um, in a word, no
that scheme relies entirely upon there being no missing user id numbers
that's pretty unreasonable, in my view
-
Apr 8, 2009, 11:52 #5
- Join Date
- Dec 2005
- Posts
- 964
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I Must admit... R937 is right... It doesn't solve the issue if there is no users above or under the user... Does anybody have a solution for this?
PHP Code:$pivotUid = $new_userid;
$min = $pivotUid-3;
$max = $pivotUid+3;
$sql = "SELECT u.fname, u.lname, u.country, user_points.points FROM ".$prefix."_users cu
INNER JOIN ".$prefix."_users u ON u.new_userid = cu.new_userid
INNER JOIN ( SELECT AVG(point) points, userid FROM ".$prefix."_GA_leaderboard
WHERE seasonid = $seasonid
GROUP BY userid ) user_points ON cu.new_userid = user_points.userid
WHERE cu.new_userid BETWEEN $min AND $max ORDER BY user_points.points DESC";
-
Apr 8, 2009, 13:10 #6
- Join Date
- Dec 2006
- Posts
- 182
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Try something like this:
Code:(SELECT * FROM (SELECT * FROM users WHERE userid < $pivotUid ORDER BY userid DESC LIMIT 3) as lowerthree WHERE userid < $pivotUid ORDER BY userid ASC LIMIT 3) UNION (SELECT * FROM users WHERE userid >= $pivotUid ORDER BY userid ASC LIMIT 4)
Bookmarks