MyBB Community Forums

Full Version: I have the uid, how do I find the username?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have the uid, how do I find the username (using php)?

For example the uid returns 2, so I would...?

Thanks. Big Grin
You could do:

$query = $db->simple_select("users", "username", "uid = '".$uid."'");
$username = $db->fetch_field($query, "username");

Replace $uid with the variable the uid is assigned to.
Great success, thank you very much.
Why would you do a query for this one?
MyBB has built in function get_user...
$author = get_user($uid);
echo $authorr[username];

You can also access all other user vars with these lines, for example:
echo $authorr[avatar];
returns the URL to user's avatar...
(2009-07-17, 03:46 PM)Lennart Sauter Wrote: [ -> ]Why would you do a query for this one?

Because get_user($uid) returns every field in the row, when they just want the username. Do you go into a shop to buy one newspaper, and buy all of them while you're there?

Toungue
Okay, I agree Big Grin
Better performance is a point, definately.

Kind regards
Lennart Sauter