Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: bomdsquad - kesäkuu 04, 2008, 06:28:36 IP

Otsikko: Random Member on main site
Kirjoitti: bomdsquad - kesäkuu 04, 2008, 06:28:36 IP
Hi i have a site, behind that (/forum) is the forum, I wanna show a random, activated member on the main page, with members avatar, name, link to profile and joined date, postcount.

Site is here www.initial.net.nz forum www.initial.net.nz/forum

Im ok with php&mysql I can get the member stuff ok, not sure where the avatar info is and hows best to get and display it.

ANY HELP APPRECIATED.
Otsikko: Re: Random Member on main site
Kirjoitti: [SiNaN] - kesäkuu 05, 2008, 11:33:26 AP
Hımmm, you can use this:

$member_id = 'USER_ID_HERE';
loadMemberData($member_id);
loadMemberContext($member_id);


And then you can use:

$memberContext[$member_id]['avatar']['image']

to display the avatar.

You will be able to fetch all the data about this member by this function. You can use var_dump() to see what you have in    $memberContext[$member_id].
Otsikko: Re: Random Member on main site
Kirjoitti: bomdsquad - kesäkuu 05, 2008, 05:08:03 IP
Hi, thanks for the reply but im not using the smf api so loadmemberdata() is not available, im using this:

SELECT * FROM smf_members WHERE is_activated='1' order by rand() limit 1"

I then get the member_id, which im assuming i need to use in the next statement to get a matching avatar? just need to know where the avatar info is.

thanks.
Otsikko: Re: Random Member on main site
Kirjoitti: spearfish - kesäkuu 05, 2008, 07:03:50 IP
Lainaus käyttäjältä: Sadrazam - kesäkuu 05, 2008, 11:33:26 AP
Hımmm, you can use this:

$member_id = 'USER_ID_HERE';
loadMemberData($member_id);
loadMemberContext($member_id);


And then you can use:

$memberContext[$member_id]['avatar']['image']

to display the avatar.

Try that.
Otsikko: Re: Random Member on main site
Kirjoitti: bomdsquad - kesäkuu 05, 2008, 07:08:14 IP
Hi did u read my post? $memberContext[$member_id]['avatar']['image'] is not available, im NOT using the smf API to do this, Im connecting to sql with my own thing, getting the data from smf_members, which includes the member_id, postcount, member name and date.
Otsikko: Re: Random Member on main site
Kirjoitti: spearfish - kesäkuu 05, 2008, 09:24:20 IP
Why do you need to do your own thing when there's already a system built in?  Sigh.....

Two Options for you.

1) Analyze /Sources/load.php and find where the member id array is populated, thus giving you access to all sorts of fun things
2) Look under the "avatar" column of smf_members (Shocker, I know).  If it's an absolute URL there you go, if it's relative, it's relative to forum/avatars
Otsikko: Re: Random Member on main site
Kirjoitti: bomdsquad - kesäkuu 05, 2008, 09:27:19 IP
Im using my own cuz the smf api interferes with another cms system.

OH GODAMMIT! I didnt see the avatar column. Duh. thanks, my random user mod/thing is completed.
Otsikko: Re: Random Member on main site
Kirjoitti: spearfish - kesäkuu 05, 2008, 09:29:49 IP
Interesting.... SSI.php is my best friend.  Not only for the functions, but it loads up all the info too.

And I know the feeling, it took me about 15 minutes to find that column when I was doing some avatar work.
Otsikko: Re: Random Member on main site
Kirjoitti: bomdsquad - kesäkuu 05, 2008, 09:40:51 IP
however....uploaded avatars are not in the avatar column, only remote and avatar gallery ones....HELP.
Otsikko: Re: Random Member on main site
Kirjoitti: ziycon - kesäkuu 05, 2008, 09:43:18 IP
Lainaus käyttäjältä: Sadrazam - kesäkuu 05, 2008, 11:33:26 AP
Hımmm, you can use this:

$member_id = 'USER_ID_HERE';
loadMemberData($member_id);
loadMemberContext($member_id);


And then you can use:

$memberContext[$member_id]['avatar']['image']

to display the avatar.

You will be able to fetch all the data about this member by this function. You can use var_dump() to see what you have in    $memberContext[$member_id].
I'm having the same issue, trying to display a avatar based on the user id, i've used the above code but i get this error:
LainaaNotice: Undefined variable: memberContext in C:\Apache\htdocs\sys_config\sql.php on line 658
Otsikko: Re: Random Member on main site
Kirjoitti: bomdsquad - kesäkuu 05, 2008, 09:48:01 IP
Hi, this is a diff kinda thing here man, Im not using the SMF code, only the database.

Im using this:$mSQLm = mysql_query("SELECT * FROM smf_members WHERE is_activated='1' AND posts > 0 order by rand() limit 1");
while($mms = mysql_fetch_array($mSQLm))
{
$M_ID = $mms["ID_MEMBER"];
$M_NAME = $mms["memberName"];
$M_POSTCOUNT = $mms["posts"];
$M_AVATAR = $mms["avatar"];

if(file_exists("forum/avatars/$M_AVATAR"))$AVATAR = "forum/avatars/$M_AVATAR";
else
if (fopen($M_AVATAR, "r"))$AVATAR = "$M_AVATAR";
else
$AVATAR = "images/logo3i.jpg";


and just noticed that uploaded avatars are not listed here...awaiting help.

Undefined variable means your error reporting is too high, or if you wanna be anal about your code, you need to declare EVERTHING.
Otsikko: Re: Random Member on main site
Kirjoitti: spearfish - kesäkuu 05, 2008, 09:50:53 IP
What is displayed in the "avatar" column if the avatar is an uploaded one?
Otsikko: Re: Random Member on main site
Kirjoitti: ziycon - kesäkuu 05, 2008, 09:52:25 IP
Lainaus käyttäjältä: spearfish - kesäkuu 05, 2008, 09:50:53 IP
What is displayed in the "avatar" column if the avatar is an uploaded one?
its a blank field/NULL
Otsikko: Re: Random Member on main site
Kirjoitti: bomdsquad - kesäkuu 05, 2008, 09:53:19 IP
which begs the question...where the hell is it??
Otsikko: Re: Random Member on main site
Kirjoitti: spearfish - kesäkuu 05, 2008, 10:27:00 IP
Under the smf_attachments section.

If the column "id_member" is not zero, I'm fairly certain that means it's an avatar.  The filename is listed under the "filename" column, and it should be wherever you specified attachments go.
Otsikko: Re: Random Member on main site
Kirjoitti: bomdsquad - kesäkuu 05, 2008, 11:35:50 IP
w00t. all done! thanks guys. works perfect.
Otsikko: Re: Random Member on main site
Kirjoitti: [SiNaN] - kesäkuu 06, 2008, 05:20:03 AP
Lainaus käyttäjältä: ziycon - kesäkuu 05, 2008, 09:43:18 IP
I'm having the same issue, trying to display a avatar based on the user id, i've used the above code but i get this error:
LainaaNotice: Undefined variable: memberContext in C:\Apache\htdocs\sys_config\sql.php on line 658

$memberContext variable must be in globals.
Otsikko: Re: Random Member on main site
Kirjoitti: bomdsquad - kesäkuu 14, 2008, 10:29:40 IP
whoo wrks perfect, worked out what kind of avatar is used, checks if it exists, if not uses a default one, also does this if user didnt even choose an avatar :) gets post count as well but not used. uses no SSI :)