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
https://forums.phpfreaks.com/topic/45924-the-where-clause-and-columns/
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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.