473,513 Members | 8,991 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to check if image is in database and if not display default image?

ilya Kraft
134 New Member
Hello,

I came across following problem. I have a table where I store user profile images, but I want to display default image if user has no image uploaded. what I do is I look into "profile_images" table where $owner_id=$user_id. I need to figure how to do something like this:

This is not a real code, just the logic

Expand|Select|Wrap|Line Numbers
  1. (Select all from "profile_images" where $owner_id=$user_is)
  2. if user has uploaded an image (so table is not empty) set the image file as user profile picture
  3. else if table is empty set image with id=0 as user image (so set default image as user profile image)
  4.  
Jun 16 '11 #1
8 3621
Dormilich
8,658 Recognized Expert Moderator Expert
something like
Expand|Select|Wrap|Line Numbers
  1. SELECT COALESCE(`user_image`, 'default_image') FROM `image_table` WHERE …
?
Jun 16 '11 #2
ilya Kraft
134 New Member
Wow,

Hi thnx for reply. Em I really don't understand what you did there ))) Can you please explain what is "COALESCE"?
So far I understood that we take user_image and default_image from image_table where it is equal to user's id, but how would I check if user has uploaded an image? and if not show default image?
I'm interested in something like this something like

Expand|Select|Wrap|Line Numbers
  1. SELECT ('user_image')FROM 'image_table' WHERE image_id=$user_id
  2. if file exists <<<< what do I write here?
  3. $user_image=row[user_image];
  4. else if file doesn't exist  <<<< what do I write here?
  5. $user_image='<img src="http://bytes.com/images/deafult.jpg />"'
  6.  
Thank You
Jun 16 '11 #3
Dormilich
8,658 Recognized Expert Moderator Expert
what COALESCE() does. essentially another way of saying if `user_image` IS NULL use 'default_image'
Jun 16 '11 #4
ilya Kraft
134 New Member
ouuu I see,

so I actually don't need to do all of that complicated stuff instead I can use COALESCE. Alright this is cool ))), but does it mean that default image would be stored separately for each user? I mean say I have 200 users, does this mean that I would have 200 default images saved in database for each of them? And also how do I upload default image so it is automatically stored in 'default' field? for each user?

Thank You )
Jun 16 '11 #5
Dormilich
8,658 Recognized Expert Moderator Expert
normally you would only have one default image, don’t you? no need to save it in the user’s data.
Jun 16 '11 #6
ilya Kraft
134 New Member
Sory for asking soo many questions, I'm still quiet new to this stuff ))) But how do I save it in users data? I have a table named "myMembers" where I save things like "id,username,e-mail etc." I know how to save those, but how do I set default_image so it is always same for all users? also how do I upload it to mySQL? I know how to upload images to databases from website, but have no idea on how to do it from phpMyAdmin.
Jun 16 '11 #7
Dormilich
8,658 Recognized Expert Moderator Expert
that depends on how you store the image. if you just save the image path you can define it in the table declaration: user_image VARCHAR(100) DEFAULT 'path/to/default_image.png'. if you save the image data itself it may be more complicated.
Jun 16 '11 #8
ilya Kraft
134 New Member
ouuu ok I think I can continue it from here ))) thank you very much )))
Jun 16 '11 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

9
1966
by: Wally | last post by:
I am trying to display images from an Access 2000 database and I get an error "Invalid Parameter Used" when I execute the code line "picBLOB.Image = Image.FromStream(stmBLOBData)" in my Visual...
1
4150
by: Thubaiti | last post by:
Hi, I have an image web control with other web controls.. <asp:Image id="itemImage" runat="server"></asp:Image> <asp:Label id="itemNameLabel" runat="server"></asp:Label> <asp:Label...
0
1223
by: Tim::.. | last post by:
Please, please, please help!!! I have a datagrid that displays a list of contacts on our intranet site using the ActiveDirectory as it's main Data Source. I want to be able to show an image of...
1
1331
by: KitKat | last post by:
With the help of kind, brilliant folks, I have been working on this program that uses a combo box selection to display six different jpgs. The jps are a time stamp, and the files are located in six...
18
6487
by: Auto | last post by:
Hello, I would like to know how do display an image into a Gridview (ASP.NET 2.0) taken directly from a DataBase, NOT using an URL, like described in this article: ...
3
7903
by: Paul Cheetham | last post by:
Hi, I have an application that will display user-defined images in some asp:image controls. (sets the ImageURL, and is always built from the site root) The problem comes when the images...
7
3720
by: dragiton | last post by:
SA Upload SQL Database variable types (image upload and storage) I am having trouble with the SA Upload utility. The following code used to work correctly. However, I lost my database and had to...
4
8281
selvasoft
by: selvasoft | last post by:
Hi Please help me i want display all images from my database. but here my code that will display only one image from database. But i want all images, any one help me. <html> <head>...
0
1100
by: praveen kumar m | last post by:
Hi All, Please any one rectify my problem. I added hotspots on image button or image map from code behind(dynamically). When I click the particular place on image button and that time...
0
1246
by: David Kawlni | last post by:
Database backend:PostgreSQL Database Name: MoviesDirectory Table Name: picture Column: img DataType:bytea First, I store my uploaded images which may be either .jpg,.gif,.png with the following...
0
7373
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7094
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5677
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5079
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
452
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.