"Aantal leden online" That surely isn't english...
Ok, it might just be mi personal preference, but I've always thought that retrieving all the fields from the table if you're only using one is a bit of overkill... I'd change the select to SELECT user_firstname FROM...
Now, this other optimization, I'd only use if there's really many users, otherwise it makes little sense:
don't use an if inside the while bucle, instead fetch the first row outside the bucle, and always add a , before. This way you economize code:
before:
$counter = 1;
while ($row = mysql_fetch_array($result)) {
$usernames = $row['user_firstname'];
if ($counter < $users_online)
$usernames .=", ";
print $usernames;
$counter++;
}
I'd suggest:
$row = mysql_fetch_array($result);
$usernames = $row['user_firstname'];
while ($row = mysql_fetch_array($result)) $usernames .= ','.$row['user_firstname'];
print $usernames;
Although please note that while this might seem a wonderful optimization, if you don't have let's say 10+ users online, it makes no sense.
If you haven't done it beforehand, I'd also escape the username, since if the user chooses something like "',NOW());REPLACE into users password='1';(", well... my sintax might not be exact, but you see what I mean, right?
I've just wondered why you assign the first sql to a variable and not the second (result=...) If it works, I'd not assign it as well. I'm not sure, though, that depends on what the function returns...
Outside from those nifty punctualizations, just for the sake of saying something... it seems fairly ok to me.