Welcome Guest, Not a member yet? Register   Sign In
If avatar
#1

[eluser]benfike[/eluser]
I have an avatar field in my users table. Users van upload avatars. And if a user not upload a avatar the avatar == '' and this time i wanted to show a default avatar but if avatar have data i wanted to show this . Now show with this code: <img src=''>avatar;?&gt; sorry for my english. Ty the help.
#2

[eluser]IamPrototype[/eluser]
Code:
if ($this->user_model->get_field('avatar', $user_id) {
// user avatar
} else {
// default avatar
}

What it does is to get the avatar field from your table with the given user_id - can be any number - I don't know how you get the avatar field, so I just wrote a totally RANDOM call to a user model, which doesn't exists. But all you do is to check if your avatar field is empty or not and show the image.

Any code of yours would be nice, thanks.
#3

[eluser]Gordaen[/eluser]
I'd throw an empty() function in that check to make it clearer.
#4

[eluser]jedd[/eluser]
Ahh .. speculative coding. My favourite type. Smile

I'd have a directory that the files were loaded into - called something imaginative like ./avatars/

The avatar file upload process would do the vetting (including staging by moderators if you want) and rename the file to the user-id.png (I'd convert to a consistent format on the way in - not a huge fan of jpeg).

I'd have a model function that would return the avatar for a given user, and that would be a link to an image file - if the user existed it'd point to the user_id.png file, otherwise it'd point to default.png - or some similar logic. The avatar-lookup method would *always* return a pointer to an image file, mind.

I'm a big fan of not storing image blobs within database tables too, btw.

But I'm not quite sure what the actual problem is - the original question seems to pose a fairly straightforward problem of identifying if a record in a table exists, and then acting differently based on the results of that lookup. I feel I'm missing something.




Theme © iAndrew 2016 - Forum software by © MyBB