11
jordi_rc
Re: Random Member ... ?
  • 2006/10/10 20:46

  • jordi_rc

  • Not too shy to talk

  • Posts: 114

  • Since: 2006/8/21


Hello.

I just have read this some minutes ago, tested in my site and find the code great, but I can contribute with some improvements:


Quote:


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

echo "
";
echo "Random member:
";
echo "$random_member[uname]
";
echo "avatar";
echo "
";




This way, it will work perfect for any XOOPS version and template. Using div instead of p, and using echo instead of print, it will use the XOOPS theme perfectly.
It also has a syntax error, at least if you use it on Linux, in img src, you must add a . before the /.
src='./uploads/
and not
src='/uploads/
or it won't load the image.

And after this, please tell me how to display the last member joined, and how to add 2 links to roll from one member to the precedent or the following, under the image.
This is to make a block showing the last member that joined.

Thanks.

Jordi
"Battles are fought by those with the courage to believe. They are won by those who find the heart to share." -MANOWAR

12
Cuidiu
Re: Random Member ... ?
  • 2006/10/30 23:56

  • Cuidiu

  • Quite a regular

  • Posts: 358

  • Since: 2006/4/23


UPDATE: Never mind. I found it. I forgot to switch out "xoops" of xoops_users with the name we're using.
------------------------------
I'm using version 2.2.4 and neither one of these codes worked for me. All I see is "Random member". I've saved the custom block as php. Could it be due to my version of MySQL 3.23.58?
[size=x-small]Working sites:
XOOPS 2.0.16 PHP 5.2.2, MySQL 5.0.24a-standard-log, Apache/2.0.54 (Unix)
XOOPS 2.2.4, PHP 4.3.10, MySQL 3.23.58, Apache/1.3.33 (Unix)[/size]

13
Cuidiu
Re: Random Member ... ?
  • 2006/10/31 0:49

  • Cuidiu

  • Quite a regular

  • Posts: 358

  • Since: 2006/4/23


Actually, I do need help. This code is showing inactive members. Is it possible to exlude the inactive members fairly easily?

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

echo "
";
echo "Random member:
";
echo "$random_member[uname]
";
echo "avatar";
echo "
";
[size=x-small]Working sites:
XOOPS 2.0.16 PHP 5.2.2, MySQL 5.0.24a-standard-log, Apache/2.0.54 (Unix)
XOOPS 2.2.4, PHP 4.3.10, MySQL 3.23.58, Apache/1.3.33 (Unix)[/size]

14
jordi_rc
Re: Random Member ... ?
  • 2006/10/31 6:16

  • jordi_rc

  • Not too shy to talk

  • Posts: 114

  • Since: 2006/8/21


What is an inactive member? Why do you want to hide them?

Jordi
"Battles are fought by those with the courage to believe. They are won by those who find the heart to share." -MANOWAR

15
Cuidiu
Re: Random Member ... ?
  • 2006/10/31 7:31

  • Cuidiu

  • Quite a regular

  • Posts: 358

  • Since: 2006/4/23


I use a highly customized version of 2.2.4. There are several reasons why. For instance, a member becomes inactive if they do not renew their membership. That way, if they renew later, they do not have to input their information again. If they do not renew after a certain time, they will be deleted.

Can anyone else help with this? I'd really like to show random users that are active. I'd also like to show more than one at a time.

Thanks,
C

Quote:
jordi_rc wrote:
What is an inactive member? Why do you want to hide them?

Jordi
[size=x-small]Working sites:
XOOPS 2.0.16 PHP 5.2.2, MySQL 5.0.24a-standard-log, Apache/2.0.54 (Unix)
XOOPS 2.2.4, PHP 4.3.10, MySQL 3.23.58, Apache/1.3.33 (Unix)[/size]

16
Mithrandir
Re: Random Member ... ?

Quote:
mysql_fetch_assoc(mysql_query(

Rather use the database object - that's why it is there.

To only get active members, add a clause of

WHERE level > 0
"When you can flatten entire cities at a whim, a tendency towards quiet reflection and seeing-things-from-the-other-fellow's-point-of-view is seldom necessary."

Cusix Software

17
Cuidiu
Re: Random Member ... ?
  • 2006/10/31 19:17

  • Cuidiu

  • Quite a regular

  • Posts: 358

  • Since: 2006/4/23


Thank you! Your reply is much appreciated!
C

Quote:
Mithrandir wrote:
Rather use the database object - that's why it is there.

To only get active members, add a clause of

WHERE level > 0
[size=x-small]Working sites:
XOOPS 2.0.16 PHP 5.2.2, MySQL 5.0.24a-standard-log, Apache/2.0.54 (Unix)
XOOPS 2.2.4, PHP 4.3.10, MySQL 3.23.58, Apache/1.3.33 (Unix)[/size]

18
Cuidiu
Re: Random Member ... ?
  • 2006/12/15 21:25

  • Cuidiu

  • Quite a regular

  • Posts: 358

  • Since: 2006/4/23


I'm back to trying to get this worked out and making a little progress. I would like to do two things.
1) Use the database object as Mithrandir suggested.
2) Display a list of 10 members at a time.
Currently, only one member shows no matter what number I use in the limit (though I don't actually know what that's for). And all my attempts to use the database object have failed.

I am also excluding 2 user IDs. As you can see, I know very little PHP so please be gentle.

Here is what I've got in a custom block so far:
$random_member mysql_fetch_assoc(mysql_query("SELECT uid, uname FROM mydbname_users WHERE level>0 AND uid>1 ORDER BY RAND() LIMIT 1"));
if 
$random_member[uid] == '4' || $random_member[uid] == '215')
echo 
"";
else {
echo 
"";
echo 
"$random_member[uid]'>$random_member[uname]";}

Would someone please help me correct this?

TIA,

C
[size=x-small]Working sites:
XOOPS 2.0.16 PHP 5.2.2, MySQL 5.0.24a-standard-log, Apache/2.0.54 (Unix)
XOOPS 2.2.4, PHP 4.3.10, MySQL 3.23.58, Apache/1.3.33 (Unix)[/size]

19
Mithrandir
Re: Random Member ... ?

ok, I give in.

This should work:
$member_handler xoops_gethandler('member');
$criteria = new CriteriaCompo(new Criteria('level''0''>'));
$criteria->add(new Criteria('uid'"(1,4,215)""NOT IN") );
$criteria->setSort('RAND()');
$criteria->setLimit(10);
$users $member_handler->getUserList($criteria);
foreach (
$users as $uid => $uname) {
    echo 
".XOOPS_URL."/userinfo.php?uid=".$uid."'>".$uname."";
}

or if it doesn't, this should:
global $xoopsDB;
$sql "SELECT uid, uname FROM ".$xoopsDB->prefix("users")." WHERE level > 0 AND uid NOT IN (1,4,215) ORDER BY RAND() LIMIT 10";
$result $xoopsDB->query($sql);
while (list(
$uid$uname) = $xoopsDB->fetchRow($result) ) {
    echo 
".XOOPS_URL."/userinfo.php?uid=".$uid."'>".$uname."";
}
"When you can flatten entire cities at a whim, a tendency towards quiet reflection and seeing-things-from-the-other-fellow's-point-of-view is seldom necessary."

Cusix Software

20
Cuidiu
Re: Random Member ... ?
  • 2006/12/15 22:20

  • Cuidiu

  • Quite a regular

  • Posts: 358

  • Since: 2006/4/23


Ah, success! The first set of code worked. Thank you for giving in, Mith. I did spend time searching through similar code and trying to work it through but my attempts failed. I want to learn more PHP so that I don't have to bug you nice folks as much, but my day job keeps getting in the way! Please know your help is much appreciated!
C
Quote:

Mithrandir wrote:
ok, I give in.

This should work:
$member_handler xoops_gethandler('member');
$criteria = new CriteriaCompo(new Criteria('level''0''>'));
$criteria->add(new Criteria('uid'"(1,4,215)""NOT IN") );
$criteria->setSort('RAND()');
$criteria->setLimit(10);
$users $member_handler->getUserList($criteria);
foreach (
$users as $uid => $uname) {
    echo 
".XOOPS_URL."/userinfo.php?uid=".$uid."'>".$uname."";
}

[size=x-small]Working sites:
XOOPS 2.0.16 PHP 5.2.2, MySQL 5.0.24a-standard-log, Apache/2.0.54 (Unix)
XOOPS 2.2.4, PHP 4.3.10, MySQL 3.23.58, Apache/1.3.33 (Unix)[/size]

Login

Who's Online

354 user(s) are online (242 user(s) are browsing Support Forums)


Members: 0


Guests: 354


more...

Donat-O-Meter

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

Latest GitHub Commits