I'm trying to select the User ID of the referrer of the currently logged in user. something like...
$query = $db->simple_select("users", "uid,username" , 'referrer');
$referrer = $db->fetch_array($query);
So the
$referrer = 1
if user was reffered by first
Untested, but you probably want something like this:
$query = $db->simple_select('users', 'referrer', "id={$mybb->user['uid']}");
$referrer = $db->fetch_field($query, 'referrer');
Be prepared for
$referrer
to be null or otherwise empty. Also, you should probably ensure that there is a logged in user before calling this code, i.e., that
$mybb->user['uid'] != 0
.
It's generating an SQL error.
Please share the error message.
Oh, wait:
id
should be
uid
in my (untested) code. So, the code should be:
$query = $db->simple_select('users', 'referrer', "uid={$mybb->user['uid']}");
$referrer = $db->fetch_field($query, 'referrer');
It works fine now, Thank you.
We dont need query to do this
(2021-02-08, 04:48 PM)Supryk Wrote: [ -> ]We dont need query to do this
As Supryk said, no need to do a query.
$mybb->user['referrer'];
You only need to query if it is for another user than the logged in user.
You guys are right. I had a lapse there.
As a general rule, anytime you need data about the current user you can use $mybb->user['fieldname'] and if you need usergroup permissions you use $mybb->usergroup['permission_name'].