amazing Posted April 6, 2007 Share Posted April 6, 2007 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. Quote Link to comment Share on other sites More sharing options...
jscix Posted April 6, 2007 Share Posted April 6, 2007 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.