Add a List ONLY Certain Membergroup in forum!

Started by ROGUE-Master, April 27, 2004, 05:33:18 PM

Previous topic - Next topic

ROGUE-Master

I just learned about your SSI news thing and just implemented it here: http://www.clanrogue.com/news.php

Its really awsome but I want to take it one step further and let it list my members, BUT ONLY ONE member group. A list by only one membergroup feature would be very easy to do and many websites will benefit from this!


Springer

So you want to use the member group as your roster.  It is a good idea.

Grudge

#3
All members or just members online?

If it's the latter (just online) then in function ssi_whosOnline, just add to the query WHERE ID_GROUP = 1 (that would just show admins).

If it's all members then do this (I haven't checked this code - it's just a quick hack).

function ssi_showMembers($output_method = 'echo')
{
global $scripturl, $db_prefix, $txt;

// Load the member group users
$result = db_query("
SELECT
mem.ID_MEMBER, mem.realName, mem.memberName
FROM {$db_prefix}members AS mem
WHERE mem.ID_GROUP = 1 OR FIND_IN_SET(1, mem.additionalGroups)
ORDER BY mem.realName", __FILE__, __LINE__);

$return['users'] = array();
while ($tmp = mysql_fetch_assoc($result))
{
$link = '<a href="' . $scripturl . '?action=profile;u=' . $tmp['ID_MEMBER'] . '">' . $tmp['realName'] . '</a>';

$return['users'][] = array(
'id' => $tmp['ID_MEMBER'],
'username' => $tmp['memberName'],
'name' => $tmp['realName'],
'href' => $scripturl . '?action=profile;u=' . $tmp['ID_MEMBER'],
'link' => $link,
'is_last' => false
);
}
mysql_free_result($result);

$return['num_users'] = count($return['users']);

if (!empty($return['users']))
$return['users'][count($return['users']) - 1]['is_last'] = true;

if ($output_method != 'echo')
return $return;

foreach ($return['users'] as $user)
echo $user['link'], !$user['is_last'] ? ', ' : '';
}


It's just a quick copy and paste job but it may work - try it!
I'm only a half geek really...

Springer

If I understand him correctly I think he wants to display all of one member group.

Such as you create a group called "Rogue Members."  Then anyone who belongs in that member group would be displayed regardless of online status. 

In a clan setting this would be very helpfull in keeping up with rosters.  (wish I had thought of it)  Add a couple of custom feilds and another image instead of avatar/sig to the members profiles and your done :)

Grudge

Well - the code I posted should do that. That will only work for primary membergroups though. May want to modify the query to be this:

WHERE mem.ID_GROUP = 1 OR FIND_IN_SET(1, mem.memberGroups)

Instead of just "WHERE mem.ID_GROUP = 1"
I'm only a half geek really...

ROGUE-Master

So will that will display a certain membergroup?

And where do I put that code in what file?

(This should really be put in SMF because many people need it)

Springer

If already written, and works, might as well let everyone know :b

Rogue if you get this working let me know.  I'm rather curious about it myself.

Grudge

ROGUE,

Just copy and paste that whole code into SSI.php. To use it just use it like you do any other SSI function but call showMembers (check out ssi_examples.php if you haven't used SSI before). The membergroup is hard coded in the example. To set the membergroup where it says:
WHERE mem.ID_GROUP = 1 OR FIND_IN_SET(1, mem.memberGroups)

Change the 1 to the ID number of whichever membergroup you want to list (1 is admin). I can update the function to take a variable to select the membergroup if you wish but if it's the same group each time just hardcode it.

PS - I've updated the function code in the previous post so the big chunk is all you need.
I'm only a half geek really...

ROGUE-Master

#9
Ok I put that function in my SSI.php now i'm going to put this function on one of my pages:

include("http://www.clanrogue.net/SMF/SSI.php?ssi_showMembers"); 

(The above does nothing so I know im missing something)

What else do I have to add to that to get a certain membergroup. I'd like to make it show a group called "ROGUE Member". Also would it be possible to show multiple groups at the same time?

Oldiesmann

#10
put this at the beginning of the page (before anything else):

require('../SSI.php');

Also, it should be

include_once("http;//www.clanrogue.net/SMF/SSI.php?ssi_function=showMembers");

You may have to edit the code for that function to get it to show the membergroup you want...

Grudge

IF you're using SHTML look at this example page:

http://www.simplemachines.org/community/ssi_examples.shtml

Should probably look more like:
<!--#include virtual="./SMF/SSI.php?ssi_function=showMembers" -->

Bear in mind that case is important too. If you're using php look at the same url but ssi_examples.php
I'm only a half geek really...

ROGUE-Master

I should have been more clear.

I'm not looking for members that are online in a membergroup I just want a list of ALL people in a certain membergroup. I am using PHP and I have looked at both SSI pages.

1. All I want to know is how to edit the code you gave me which I placed in my SSI.php.
2. And how do I display it properly on the PHP page (www.clanrogue.net/news.php) (I currently have include_once("http;//www.clanrogue.net/SMF/SSI.php?ssi_function=showMembers");

ROGUE-Master

And on: "Just copy and paste that whole code into SSI.php. To use it just use it like you do any other SSI function but call showMembers (check out ssi_examples.php if you haven't used SSI before). The membergroup is hard coded in the example. To set the membergroup where it says:
WHERE mem.ID_GROUP = 1 OR FIND_IN_SET(1, mem.memberGroups)

Change the 1 to the ID number of whichever membergroup you want to list (1 is admin). I can update the function to take a variable to select the membergroup if you wish but if it's the same group each time just hardcode it."

I wasn't really sure what you mean but I'm guessing change

WHERE mem.ID_GROUP = 1 OR FIND_IN_SET(1, mem.memberGroups) to

WHERE mem.ID_GROUP = 5 OR FIND_IN_SET(5, mem.memberGroups)

Grudge

Yes. What you have done IN SSI is fine and it doesn't just show online members.

To call it in PHP follow examples here:

http://www.simplemachines.org/community/ssi_examples.php

Example would be:

require("/home/simple/public_html/community/SSI.php");
ssi_showMembers();


Changing the path to whatever yours is (note its the absolute path NOT the URL). You can find out the exact path by going to www.yourforum.com/smf/ssi_examples.php - it's on the top line)
I'm only a half geek really...

ROGUE-Master

#15
 :-*

Ok heres the page:
http://clanrogue.net/news2.php

Heres the coding of that page:
<?php

require("/home/virtual/site20/fst/var/www/html/SMF/SSI.php");

ssi_showMembers();

?>


Heres the line in the SSI.php that had the error:
ORDER BY mem.realName", __FILE__, __LINE__);

What am I doing wrong?

Grudge

Firstly, next time post the whole error message as only admins see the database error (I only say an error had occured message!)

Secondly, on this line:


mem.ID_MEMBER, mem.realName, mem.memberName,


remove the comma at the end - sorry.
I'm only a half geek really...

ROGUE-Master

Ok I added the comma and it fixed that error. Now it comes up with a new error.

But first, heres the error that you couldn't read before:

Database Error
You have an error in your SQL syntax near 'FROM smf_members AS mem
WHERE mem.ID_GROUP = 1 OR FIND_IN_SET(1, mem.memberGro' at line 4
File: /home/virtual/site20/fst/var/www/html/SMF/SSI.php
Line: 1389 


Here is the new error after I removed the comma:

Database Error
Unknown column 'mem.memberGroups' in 'where clause'
File: /home/virtual/site20/fst/var/www/html/SMF/SSI.php
Line: 1389 


Here is the line of code on Line 1389:

ORDER BY mem.realName", __FILE__, __LINE__);

Grudge

Real sorry. Was late when I wrote that - messed it up. Should be mem.additionalGroups not mem.memberGroups. Hopefully that'll fix it...
I'm only a half geek really...

ROGUE-Master

Yay! It now kind of works! http://clanrogue.net/news2.php
It is currently listing the Admins who are membergroup 1.

It also worked when I changed

WHERE mem.ID_GROUP = 1 OR FIND_IN_SET(1, mem.additionalGroups)

to

WHERE mem.ID_GROUP = 2 OR FIND_IN_SET(2, mem.additionalGroups)
which displayed the Global Mods. 3 didn't work because I didn't have any mods.
But the group I want to show is called "ROGUE Member" which is the 6th membergroup down on the "Manage Membergroup" page. I tired replacing the two numbers with 6 but that did not work. How do I display them? Also how can I show multiple member groups at once. (Which line to edit)



The second part of what I would like is that currently the members are listed one after another with a comma. Could you change the code so they list one on top of another?
e.g.
ROGUE-Master
ROGUE-Game
instead of ROGUE-Master, ROGUE-Game.


Thanks for your help agian.

Advertisement: