1
deka87
random users block
  • 2009/10/15 10:30

  • deka87

  • Friend of XOOPS

  • Posts: 1125

  • Since: 2007/10/5


hi guys,

is there any idea on how to make a block that will show random users by a definite group? thanks in advance

2
ghia
Re: random users block
  • 2009/10/15 10:56

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


See this and this.

3
mjoel
Re: random users block
  • 2009/10/15 11:44

  • mjoel

  • Quite a regular

  • Posts: 325

  • Since: 2006/12/9


and this

4
deka87
Re: random users block
  • 2009/10/15 12:39

  • deka87

  • Friend of XOOPS

  • Posts: 1125

  • Since: 2007/10/5


thanks guys. ok i found this:

$random_member mysql_fetch_assoc(mysql_query("SELECT uid, uname, user_avatar FROM xoops_users ORDER BY RAND() LIMIT 1"));

print 
"<p align='center'>";
print 
"<strong>Random member:</strong><br />";
print 
"<a href='userinfo.php?uid=$random_member[uid]'>$random_member[uname]</a><br />";
print 
"<img src='/uploads/$random_member[user_avatar]' alt='avatar' />";
print 
"</p>";


but it won't work on XOOPS 2.3.3. does anybody know how do i correct it?

5
ghia
Re: random users block
  • 2009/10/15 15:23

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


Did you think about the right table prefix?
(BTW, best examples are always in the back.)

6
deka87
Re: random users block
  • 2009/10/15 15:37

  • deka87

  • Friend of XOOPS

  • Posts: 1125

  • Since: 2007/10/5


oh right this one works

global $xoopsDB
$sql "SELECT uid, uname, user_avatar  FROM ".$xoopsDB->prefix("users")." WHERE level > 0 AND uid NOT IN (1) AND user_avatar <> 'blank.gif' ORDER BY RAND() LIMIT 10"
$result $xoopsDB->query($sql); 
while (list(
$uid$uname,$user_avatar) = $xoopsDB->fetchRow($result) ) 

echo 
"<img src='./uploads/".$user_avatar."'alt='Avatar'></a><br />"
echo 
"<a href='".XOOPS_URL."/userinfo.php?uid=".$uid."'>".$uname."</a><br />"
}


thanks for the links guys

7
deka87
Re: random users block
  • 2009/10/15 17:17

  • deka87

  • Friend of XOOPS

  • Posts: 1125

  • Since: 2007/10/5


one more thing. it shows random users whatever their group is. how to I restrict it to show users from the group with id = 6? thanks

8
ghia
Re: random users block
  • 2009/10/15 18:24

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


Try
$sql "SELECT u.uid, u.uname, u.user_avatar  FROM ".$xoopsDB->prefix("users")." u 
LEFT JOIN "
.$xoopsDB->prefix("groups_users_link")." g on u.uid = g.uid 
WHERE g.groupid = 6 AND u.level > 0 AND u.uid NOT IN (1) AND u.user_avatar <> 'blank.gif' 
ORDER BY RAND() LIMIT 10"
;


9
deka87
Re: random users block
  • 2009/10/16 11:41

  • deka87

  • Friend of XOOPS

  • Posts: 1125

  • Since: 2007/10/5


oh thats right ghia. it works. thanks!

also how do display some additional information from the user profile table like his coutry or custom fields?

10
ghia
Re: random users block
  • 2009/10/16 14:34

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


Try
$sql "SELECT u.uid, u.uname, u.user_avatar, p.country, p.field1, p.field2  FROM ".$xoopsDB->prefix("users")." u 
LEFT JOIN "
.$xoopsDB->prefix("groups_users_link")." g on u.uid = g.uid 
LEFT JOIN "
.$xoopsDB->prefix("profile_profile")." AS p ON u.uid=p.profile_id
WHERE g.groupid = 6 AND u.level > 0 AND u.uid NOT IN (1) AND u.user_avatar <> 'blank.gif' 
ORDER BY RAND() LIMIT 10"
;

field1 and field2 are to be replaced with the real profile names.
(It is assumed that the fields may be visible to all groups.)

Login

Who's Online

214 user(s) are online (122 user(s) are browsing Support Forums)


Members: 0


Guests: 214


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Mar 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits