Creating an Avatar System

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Teonnyn
Forum Commoner
Posts: 58
Joined: Tue Dec 23, 2008 4:07 am

Creating an Avatar System

Post by Teonnyn »

I am trying to figure out the best way to build an avatar system for my users. I figure it's most likely as simple as an If (!'$user'avatar) then display no-avatar.jpg else get database query, display currently selected avatar. However, it's a bit confusing. Could anyone tell me if I'm on the right track or point me in the right direction if I am not?
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Creating an Avatar System

Post by papa »

You probably have a user table in your database, create a avatar field with the name for that image.

Then when fething the user info you could simply use, for example:

Code: Select all

 
 
//mysql fetch etc
 
$avatar = !empty($row['avatar']) ? "<img src=\"path/to/avatar/{$row['avatar']}.gif\" />" : "";
 
echo $avatar;
 
 
 
Post Reply