Jump to content

The where clause and columns


amazing

Recommended Posts

I have a table with an images column for members that I need to show results from. The only problem is that I only want the results to show where people have actually uploaded an image. I think this involves the "where" clause but not sure how to do it.

 

Also, is there an if/else statement I can use that says if no pic is found use default pic instead?

 

Sorry if this seems elementary but I'm still a newbie.  :(

Link to comment
Share on other sites

What I usually do with image uploads is create a table which has two or three columns,

 

Usually a unique identifier for the image, and depending what im doing, an identifier for the user the image belongs to, (and or a file-name also depending on what im doing) for example:

 

****************

PK - primary key

FK - foreign key

| whatever | - Column

 

| imgid(PK) | userid(Fk) | imagefiledetails |

 

*************************

What I do is name the image using the unique ID that is created upon adding a new entry to the images table. (The  imgid)

Aftering uploading an image, use the imgid to name your images (E.G: USERIMG + the imgid number) 

 

When you want to check if a user has an image uploaded, retrieve the users ID using their username, and/or whatever you are using to identify them, which should also be a column in your images table to associate the user with his/her image.

 

If you retrieve a result from the images table, you can be pretty sure the user has an image uploaded, so just retrive the imgid, and link the image named USERIMG  + The Retrived IMGID

 

$example1 = mysql_query("SELECT users.USERID FROM users WHERE users.username='USERNAME'");

$rete1 = mysql_fetch_row($example1);

$example2 = mysql_query("SELECT images.imgid FROM images WHERE images.USERID='$rete1[0]'");

$rete2 = mysql_fetch_row($example2);

 

the image name should be:

 

$theimg = "USERIMG" . $rete2[0] . ".file-extention";

 

 

I hope that helps you, if even a little. :D

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.