MyBB Community Forums

Full Version: how to add a piece of code and get this
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Well i don't want my thing to become a "mod", i want a "plugin" so, i'm asking you, my plugin does a DB query when you go to the profile of someone, so i've added the query in the member.php file ok.
That works, this is the query
	$query = $db->query("SELECT username,uid FROM ".TABLE_PREFIX."users WHERE referrer='".$mybb->input['uid']."'");
	$referrals = $db->num_rows($query);
but i don't want that the users of this mod, have to edit the file member.php so i'm asking if there's another way?
I want it to be fully automated.. well tell me if it's possible.
This is for the Fast Refer 0.5 Alpha plugin,
it currently does this:
- Give referral link
- Tell in usercp how many people you have referred ( not who yet thou, that's for next version. )
- When you go to a user's profile, you see how many referrals he has got ( which is btw the above code. )

You may not use this code for your own mods, nor redistribute this code!

Thank you!
- Shadows.
You should use plugin hooks. I suggest reading up on them, but I'll give you a quick example here:
$plugins->add_hook('member_profile_start', 'referrer_count');
function referrer_count()
{
    global $referrals;
    $query = $db->query("SELECT username,uid FROM ".TABLE_PREFIX."users WHERE referrer='".intval($mybb->input['uid'])."'");
    $referrals = $db->num_rows($query); 
}
shouln't it be? Whit the global $db
$plugins->add_hook('member_profile_start', 'referrer_count');
function referrer_count()
{
    global $db, $referrals;
    $query = $db->query("SELECT username,uid FROM ".TABLE_PREFIX."users WHERE referrer='".intval($mybb->input['uid'])."'");
    $referrals = $db->num_rows($query); 
}
Yeah, you're right, I forgot that. Thanks Toungue
I missed something to; global $db, $mybb, $referrals;
$plugins->add_hook('member_profile_start', 'referrer_count');
function referrer_count()
{
    global $db, $mybb, $referrals;
    $query = $db->query("SELECT username,uid FROM ".TABLE_PREFIX."users WHERE referrer='".intval($mybb->input['uid'])."'");
    $referrals = $db->num_rows($query); 
}