MyBB Community Forums

Full Version: Add specific usergroup to a new .php file
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Okay, I will explain as much as possible.

I've created the usergroup "Platoon Members" (gid: 9), and I have created a new file, called "roster.php" and I would like all members of that group, to go onto the roster's page, just like the show team page.

It's basically the show team page, but with 1 specific usergroup.

Any suggestions/tutorials how? Thanks in advanced.
Basically use a while loop to generate a table, and here's the MySQL code you should need to run the loop correctly:
global $db;

$query = $db->query("SELECT * FROM ".TABLE_PREFIX."users WHERE usergroup='9'");

while($r = $db->fetch_array($query))
{
     //show $r['username'], $r['uid'], etc...
}
Let me know how that works for ya
(2011-11-30, 09:58 PM)fizz Wrote: [ -> ]Basically use a while loop to generate a table, and here's the MySQL code you should need to run the loop correctly:
global $db;

$query = $db->query("SELECT * FROM ".TABLE_PREFIX."users WHERE usergroup='9'");

while($r = $db->fetch_array($query))
{
     //show $r['username'], $r['uid'], etc...
}
Let me know how that works for ya

Truthfully, I'm not a very good PHP coder, I pretty much specialize in HTML. I put the code into the file correctly, and tried echoing out the username, but it brought back an error.

Direct initialization of this file is not allowed.

Please make sure IN_MYBB is defined.

It's probably a simple mistake I'm missing but I'm learning. Help is appreciated.
Mmkay you probably shouldn't be trying to make plugins if you don't know any PHP, sorry. Look at the Wiki on the basics of making a plugin, because IN_MYBB is literally the first thing covered in the demo plugin.

Maybe move this to the requests forum and see if I or another developer would be kind enough to make it for you Wink
Roster.php:

<?php
define("IN_MYBB",1);
$query = $db->simple_select("users","*","usergroup=9");

while($r = $db->fetch_array($query)){
     //show $r['username'], $r['uid'], etc...
} 
?>
That is the bare basics of it. If you want to use templates you'll need to create 2 templates for it:
roster:
<html>
<head>
<title>Roster</title>
{$headerincludes}
</head>
<body>
{$header}
<table border="0" cellspacing="1" cellpadding="4" class="tborder">
{$rows}
</table>
</table>
{$footer}
</body>
</html>

roster_row
<tr>
  <td>{$r['username']}</td>
</tr>

and do something more like this:

<?php
define("IN_MYBB",1);
$query = $db->simple_select("users","*","usergroup=9");

while($r = $db->fetch_array($query)){
     eval("\$rows .= \"".$templates->get("roster_row")."\";");
} 
eval("\$roster = \"".$templates->get("roster")."\";");
output_page($roster);
?>

Again, that is the basics of it. You can extend this as little or as much as you would want!
Or Jake can be a stud and make it real quick... Big Grin
Thank you both, and @fizz, I will be learning PHP in the coming days/week.

Just one more thing: How would I get a users Avatar, and custom profile field filled in info, for instance, I made a custom profile field called "Gamertag" and another (fid: 4 & 6) into the created table?

On the template, I created roster & roster_row. In roster_row, I have 4 lines now, with only the Username working. I need to fetch the users avatar, and their info for the custom fields.

Thanks in advanced.
Avatar:
$user['avatar']