1
hipoonios
Php code that lists users from a specific group?
  • 2010/1/4 11:57

  • hipoonios

  • Friend of XOOPS

  • Posts: 298

  • Since: 2005/9/24


I have created a group on my site called "supporters" In this group I'm adding users that have donated to my site.

What I want is a php-block that listing users from this group.

i would appreciate if someone could help my with this.

2
mjoel
Re: Php code that lists users from a specific group?
  • 2010/1/4 14:39

  • mjoel

  • Quite a regular

  • Posts: 325

  • Since: 2006/12/9


i'm not a coder...
but here's what i use to show 8 random member in a php custom block

to show only members from a group..you need to edit the sql select statement to include the groups_user_link table and groupid

my php coding sucks..let the more experience tell you how to do that

in the mean time you can test this

if the user have no avatar...it will show an image i uploaded in uploads folder called blank-avatar.gif

$count=0;
global 
$xoopsDB;
echo 
"<table><tr>";
$sql "SELECT distinct uid, uname, user_avatar FROM ".$xoopsDB->prefix("users")."  ORDER BY RAND() LIMIT 8";
$result $xoopsDB->query($sql);

while (list(
$uid$uname,$user_avatar) = $xoopsDB->fetchRow($result) ) {
$count++;
if (
$user_avatar == 'blank.gif')
{
echo 
"<td><a href='".XOOPS_URL."/userinfo.php?uid=".$uid."'><img src='".XOOPS_URL."/uploads/blank-avatar.gif' title='".$uname."' border='0' alt='".$uname."' height='48' width='48'><br />".$uname."</a></td>";
}

else

{
echo 
"<td><a href='".XOOPS_URL."/userinfo.php?uid=".$uid."'><img src='".XOOPS_URL."/uploads/".$user_avatar."' title='".$uname."' border='0' alt='".$uname."' height='48' width='48'><br / >".$uname."</a></td>";
}

if(
$count == 4)

 {

  
$count=0;

  echo 
"</tr><tr>";

 }}

echo 
"</tr></table>";

3
ghia
Re: Php code that lists users from a specific group?
  • 2010/1/4 16:01

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


See also this.

4
hipoonios
Re: Php code that lists users from a specific group?
  • 2010/1/4 18:29

  • hipoonios

  • Friend of XOOPS

  • Posts: 298

  • Since: 2005/9/24


Thanks both.

But I still need help with this.

The code you posted mjoel works. Now I need to find a way to get it from a specific group and remove the random function.

Anyone?

5
iHackCode
Re: Php code that lists users from a specific group?

would this help?

$userhandler xoops_gethandler('user');
$userhandler->table_link $xoopsDB->prefix('groups_users_link');
$userhandler->field_link "uid";
$userhandler->field_object "uid";
$criteria = new Criteria('l.groupid',2); //2 being the group id.
$criteria->setSort("o.uid");
$criteria->setOrder('DESC');//maybe add a limit.
$userobjarray $userhandler->getByLink($criteria);

6
trabis
Re: Php code that lists users from a specific group?
  • 2010/1/4 19:23

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Change $groupid (1 is for webmasters)
$groupid 1;
$count=0;
global 
$xoopsDB;
echo 
"<table><tr>";
$result $xoopsDB->query("SELECT u.uid, u.uname,  u.user_avatar FROM ".$xoopsDB->prefix("groups_users_link")." l LEFT JOIN ".$xoopsDB->prefix("users")." u ON l.uid=u.uid LEFT JOIN ".$xoopsDB->prefix("groups")." g ON l.groupid=g.groupid WHERE g.groupid=".$groupid."  ORDER BY l.groupid, u.uid");

while (list(
$uid$uname,$user_avatar) = $xoopsDB->fetchRow($result) ) {
$count++;
if (
$user_avatar == 'blank.gif')
{
echo 
"<td><a href='".XOOPS_URL."/userinfo.php?uid=".$uid."'><img src='".XOOPS_URL."/uploads/blank-avatar.gif' title='".$uname."' border='0' alt='".$uname."' height='48' width='48'><br />".$uname."</a></td>";
}

else

{
echo 
"<td><a href='".XOOPS_URL."/userinfo.php?uid=".$uid."'><img src='".XOOPS_URL."/uploads/".$user_avatar."' title='".$uname."' border='0' alt='".$uname."' height='48' width='48'><br / >".$uname."</a></td>";
}

if(
$count == 4)

 {

  
$count=0;

  echo 
"</tr><tr>";

 }}

echo 
"</tr></table>";

7
hipoonios
Re: Php code that lists users from a specific group?
  • 2010/1/4 20:31

  • hipoonios

  • Friend of XOOPS

  • Posts: 298

  • Since: 2005/9/24


Thank You ! Working fine!

8
hipoonios
Re: Php code that lists users from a specific group?
  • 2010/1/5 16:38

  • hipoonios

  • Friend of XOOPS

  • Posts: 298

  • Since: 2005/9/24


I have one more request to this.

Is it possible to do so the users is listen in alphabetic order instead of userid?

The code I use is the one Trabis last posted.

9
ghia
Re: Php code that lists users from a specific group?
  • 2010/1/5 19:10

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


Yes, replace ORDER BY l.groupid, u.uid by ORDER BY l.groupid, u.uname

10
hipoonios
Re: Php code that lists users from a specific group?
  • 2010/1/5 19:39

  • hipoonios

  • Friend of XOOPS

  • Posts: 298

  • Since: 2005/9/24


Thanks ghia!

Login

Who's Online

206 user(s) are online (113 user(s) are browsing Support Forums)


Members: 0


Guests: 206


more...

Donat-O-Meter

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

Latest GitHub Commits