MyBB Community Forums

Full Version: how to get the user title
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I have a rather strange problem. Now someone help me retrieve the user's title? So far I managed to read through the u.usertitle in the query, but it takes only one which enters the user himself. I care about the fact that this also fetch him, according to the default and group.
what is the query you have tried ?
Fetch default usertitles by joining table "mybb_usergroups" as well by joining user's usergroup (say, g.usertitle).
Then compare if u.usertitle is blank then consider g.usertitle.
(2013-12-07, 11:22 AM).m. Wrote: [ -> ]what is the query you have tried ?

$sql = $db->query("
        SELECT  u.username,  u.avatar, u.usergroup, u.displaygroup, u.title, g.usertitle
        FROM ".TABLE_PREFIX."users u
        LEFT JOIN ".TABLE_PREFIX."usergroups g
        ORDER BY u.username ASC
    ");
(2013-12-07, 11:26 AM)effone Wrote: [ -> ]Fetch default usertitles by joining table "mybb_usergroups" as well by joining user's usergroup (say, g.usertitle).
Then compare if u.usertitle is blank then consider g.usertitle.

Someone help me frame the question at the same time collecting all the data? I do not like just such things. : (
(2013-12-07, 11:26 AM)effone Wrote: [ -> ]u.usertitle
(2013-12-09, 05:13 PM)Mww51 Wrote: [ -> ]
u.title

See the difference?

http://docs.mybb.com/Database_Tables-mybb_users.html - there is even no column named 'title'.

Moreover, LEFT JOIN is kinda pointless without ON, try:
$sql = $db->query("
        SELECT  u.username,  u.avatar, u.usergroup, u.displaygroup, u.usertitle, g.usertitle, g.gid
        FROM ".TABLE_PREFIX."users u
        LEFT JOIN ".TABLE_PREFIX."usergroups g ON u.usergroup = g.gid
        ORDER BY u.username ASC
    "); 
OK. It gets the title of GID 2 (even though I am an administrator (4)), how to do to take from the set (by the user), the titles of the group and the default (ACP). So if you do not have set your, it shows him his, if it shows the default group or default.
In this regard u.title - by mistake I typed it ...
get_usertitle($uid) is defined in inc/functions_user.php Wink