MyBB Community Forums

Full Version: [Request]Auto Usergroup Change
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5
Thanks Zaher.

I have tried this but it didnt work. Can you check and advise. Thanks. Smile

Quote:## Update Usergroup ##
// Usergroup-ID Group 1 (old group)
$gid1 = "2";
$gid1a = "10";

// Usergroup-ID Group 2 (new group)
$gid2 = "10";
$gid2a = "9";

// Minimal number of posts
$minposts = "10";
$minpostsa = "10";

// Update user
if ($mybb->user['postnum'] == $minposts)
if ($mybb->user['postnum'] == $minpostsa)
{
// Update usergroup
$update_group = $db->query("UPDATE ".TABLE_PREFIX."users SET usergroup = '".$gid2."', displaygroup = '".$gid2."' WHERE uid = '".$mybb->user['uid']."' AND usergroup = '".$gid1."'");
$update_group2 = $db->query("UPDATE ".TABLE_PREFIX."users SET usergroup = '".$gid2a."', displaygroup = '".$gid2a."' WHERE uid = '".$mybb->user['uid']."' AND usergroup = '".$gid1a."'");
}
## Update Usergroup ##
?>

no no no!! not like this

if ($mybb->user['postnum'] == $minposts)
if ($mybb->user['postnum'] == $minpostsa)
{
// Update usergroup
$update_group = $db->query("UPDATE ".TABLE_PREFIX."users SET usergroup = '".$gid2."', displaygroup = '".$gid2."' WHERE uid = '".$mybb->user['uid']."' AND usergroup = '".$gid1."'");
$update_group2 = $db->query("UPDATE ".TABLE_PREFIX."users SET usergroup = '".$gid2a."', displaygroup = '".$gid2a."' WHERE uid = '".$mybb->user['uid']."' AND usergroup = '".$gid1a."'");
}
## Update Usergroup ##

it should be like this


$gid1 = "2";
$gid1a = "4";

// Usergroup-ID Group 2 (new group)
$gid2 = "4";
$gid2a = "5";
// Minimal number of posts
$minposts = "5";
$minpostsa = "10";
// Update user
if ($mybb->user['postnum'] == $minposts)
{
// Update usergroup
$update_group = $db->query("UPDATE ".TABLE_PREFIX."users SET usergroup = '".$gid2."', displaygroup = '".$gid2."' WHERE uid = '".$mybb->user['uid']."' AND usergroup = '".$gid1."'");
}

if ($mybb->user['postnum'] == $minpostsa)
{
// Update usergroup
$update_group2 = $db->query("UPDATE ".TABLE_PREFIX."users SET usergroup = '".$gid2a."', displaygroup = '".$gid2a."' WHERE uid = '".$mybb->user['uid']."' AND usergroup = '".$gid1a."'");

}
Hi Zaher,

Thanks for the tips. I shouldve known better Big Grin But it still aint working, heres my code.. Is there anything I've missed? Thanks!

## Update Usergroup ##
// Usergroup-ID Group 1 (old group)
$gid1 = "2";
$gid1a = "10";

// Usergroup-ID Group 2 (new group)
$gid2 = "10";
$gid2a = "9";

// Minimal number of posts
$minposts = "10";
$minpostsa = "30";

// Update user
if ($mybb->user['postnum'] == $minposts)
{
// Update usergroup
$update_group = $db->query("UPDATE ".TABLE_PREFIX."users SET usergroup = '".$gid2."', displaygroup = '".$gid2."' WHERE uid = '".$mybb->user['uid']."' AND usergroup = '".$gid1."'");
}

if ($mybb->user['postnum'] == $minpostsa)
{
// Update usergroup
$update_group2 = $db->query("UPDATE ".TABLE_PREFIX."users SET usergroup = '".$gid2a."', displaygroup = '".$gid2a."' WHERE uid = '".$mybb->user['uid']."' AND usergroup = '".$gid1a."'");

}
## Update Usergroup ##
?>

Note, I am changing Usergroup1 to Usergroup2... Then Usergroup2 to Usergroup3.

Zac
well where is your problem, are you trying with users with the posts specified in the variable?

Please take note that users who have these posts count before applying this code are not affected.

You should run a sql query in the phpmyadmin,
 UPDATE mybb_users SET usergroup = 'x', displaygroup = 'x' WHERE postnum >= 'y' AND usergroup = 'z'
change x, y, z to what you desite.
this will change all these options for those users who have reached this post count before applying this code. Now this code will work for those who are on the way posting thread, once any reach the desired count he will be moved to the other groupSmile

regards
would it be possible to do it for age?
(e.g. if you are a certain age then you cange usergroup)
This did not work for me too Sad
Users group does not change , after the post limit that I define Sad
Well , I did it.I prefer first method Wink
ok i have a question related to this only i want the the users of my forum be able to see the forum but cant access it till they have the certain number of posts or the group they belong too

any comments or suggestions please let me know thanks
Michael83 Wrote:A nicer solution (far less queries): Insert into global.php
## Update Usergroup ##
// Usergroup-ID Group 1 (old group)
$gid1 = "2";

// Usergroup-ID Group 2 (new group)
$gid2 = "4";

// Minimal number of posts
$minposts = "5";

// Update user
if ($mybb->user['postnum'] == $minposts)
{
// Update usergroup
$update_group = $db->query("UPDATE ".TABLE_PREFIX."users SET usergroup = '".$gid2."', displaygroup = '".$gid2."' WHERE uid = '".$mybb->user['uid']."' AND usergroup = '".$gid1."'");
}
## Update Usergroup ##
When you use this method, you have to run the following query via phpmyadmin to update all users that already have more than x posts:
UPDATE mybb_users SET usergroup = 'x', displaygroup = 'x' WHERE postnum >= 'y' AND usergroup = 'z'
x = new goup id
y = minimal post number
z = old group id

hey can some one please explain it to me where in the gobal.php i should insert the code and do i have to make a separate group for the members with posts that are required to view this forum or i will do it on its own

need some advice sorry i new to the whole php concept so sometimes take a little time to get it done

and i want to know one more thing i want all the registered users can view the forum but if they will click on it it should say they are not allowed but if the member with the required post clicks on the forum they should be able to access the forum

thanks for all the help
Hi, when I run the update query, users in my new group are transfered to Unregistered user group?? I'm sure that I got the gid and everything else right.

[edit]

My new group was empty. Maybe that was the problem.

But hey.. The user group is not automatically changing. What's up? Sad
Pages: 1 2 3 4 5