I made and submitted a hack "User Icons 1.1" just recently here but it needs quite a lot of queries on a few pages. For example it displays icons next to the user names on the who's online. The code in online.php looks like this currently:
PHP Code:
$allusers= $DB_site->query("SELECT user.username, session.location, session.lastactivity, user.userid, user.usergroupid, user.invisible, session.host, user.showemail, user.receivepm
FROM session, user
". iif($WOLguests, " LEFT JOIN user USING (userid) ", ",user") ."
WHERE session.lastactivity > $datecut
". iif(!$WOLguests, " AND session.userid = user.userid", "") ."
ORDER BY user.username
");
$moderators = $DB_site->query("SELECT DISTINCT userid FROM moderator");
while ($mods = $DB_site->fetch_array($moderators)) {
$mod[$mods[userid]] = 1;
}
$count = 0;
while ($user = $DB_site->fetch_array($allusers)) {
if ($user['userid']) { // Reg'd Member
$key = $user['userid'];
if (($userinfo["$key"]['lastactivity'] < $user['lastactivity']) or !$userinfo["$key"]['lastactivity']) {
$userinfo["$key"]['realname'] = $user['username'];
$iconavatarurl=geticonavatarurl($user['userid']);
if ($iconavatarurl!="") {
$iconavatar = "<img src=\"$iconavatarurl\" border=\"0\" alt=\"\">";
} else {
$iconavatar = "";
}
if ($bbuserinfo[userid]>0 and !($bbuserinfo[showiconavatars])) {
$iconavatar = "";
}
if ($user['usergroupid'] == 6 and $highlightadmin) {
$userinfo["$key"]['username'] = "$iconavatar<font color={whosonlineowner}><b><i>$user[username]</i></b></font>";
Note the function "geticonavatarurl" which looks like this:
PHP Code:
// ###################### Start geticonavatarurl #######################
function geticonavatarurl($userid) {
global $DB_site,$session;
if ($iconavatarinfo=$DB_site->query_first("SELECT user.iconavatarid,iconavatarpath,NOT ISNULL(iconavatardata) AS hascustom,customiconavatar.dateline
FROM user
LEFT JOIN iconavatar ON iconavatar.iconavatarid=user.iconavatarid
LEFT JOIN customiconavatar ON customiconavatar.userid=user.userid
WHERE user.userid='$userid'")) {
if ($iconavatarinfo[iconavatarpath]!="") {
return $iconavatarinfo[iconavatarpath];
} else if ($iconavatarinfo['hascustom']) {
return "iconavatar.php?userid=$userid&dateline=$iconavatarinfo[dateline]";
} else {
return '';
}
}
}
Is it possible to merge those 2 parts of code into 1 so it only needs 1 query to display the who's online instead of 1+ 1 for each icon. I tried some stuff myself but I'm really lost here.