[eluser]Michael Wales[/eluser]
I'm assuming a lot here, but let's say this is your users table:
Quote:id
username
email
password
first_name
last_name
email
avatar
created_on
I assume you are displaying some of this information on your pages (you are pulling the user's record down to display within the view):
Code:
$query = $this->db->getwhere('users', array('id'=>$id));
if ($query->num_rows() > 0) {
$this->data->user = $query->row();
}
Then to check if they have uploaded an avatar image simply:
Code:
if (!empty($this->data->user->avatar)) {
// We have a filename in this field, no need for another database call because we were
// already storing the user's record from information needed previously.
} else {
// They haven't uploaded an avatar - show the default
}
Like I said, this is a lot of assumption, but - you don't have to make one database call per piece of information. If you are already pulling down the user's information (and I don't know how you would create a website with login functionality without doing so) then just modify that query/use it's return information for this functionality.
To directly answer your question - file_exists() or a database call. It doesn't really matter - I would assume file_exists() is faster, but if you already have the database information (like I describe above), using that information you already have will be faster.