MyBB Community Forums

Full Version: Showing users avatar in online users list only showing one user
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I would like to show users' avatars on the online users list on the forum index, and I found this tutorial - http://yaldaram.com/showthread.php?tid=3784

That works great, but that's only for showing it on the actual online.php page and doesn't work on the forum index. I had a play around and decided to add the following code;

            $query = $db->simple_select("users", "*", "uid='{$user['uid']}'");
            $us = $db->fetch_array($query);

            if ($us['avatar'] != "")
            {
                $user_avatar = '<img src="'.$us['avatar'].'" alt="Avatar" title="'.$user['username'].' \'s Avatar" width="35px" height="35px">';
            }
            else
            {
                $user_avatar = '<img src="images/default_avatar.gif" alt="Avatar" title="'.$user['username'].' \'s Avatar" width="35px" height="35px">';
            }

...to my index.php file directly above these lines;

					// Properly format the username and assign the template.
					$user['username'] = format_name($user['username'], $user['usergroup'], $user['displaygroup']);

It works kind of, but it only shows one user instead of all of the ones that are online.

I don't know what bit to edit to make it show all online users. Can anyone help me? Thanks Smile

I've fixed it. I changed the beginning of the code to;

            $query2 = $db->simple_select("users", "*", "uid='{$user['uid']}'");
            $us = $db->fetch_array($query2);

...and now it works Smile
Will not that make a query by each user? That is a resources hog.
I have no idea TBH, I don't know much about this stuff Toungue I don't have many members online at any one time anyway so there wouldn't be many.

But still, does anyone know of a way to do the same thing but without increasing queries? Smile
I may get something for the online.php file, but no for the index one.