dropfaith Posted August 31, 2008 Share Posted August 31, 2008 So what im trying to do is make a script that uploads a photo(done) and then assigns it to two different mysql tables. i also need help working out a script to create thumbnails from the upload script.. the only reason i need it to create a second table is the site is for a model and i need it to display on the gallery page and the credit page the credit page will be formated like http://dropfaithproductions.com/test/pinup.php but i only want each photographer to have 4 pics and i want it to update those 4 pics if the model loads more into the gallery from him(and replace his 4 that were there) im decent in php on inserts and pulling data just wondering wht the best way to do this and a push in the right direction would be nice thanks Quote Link to comment Share on other sites More sharing options...
Psycho Posted August 31, 2008 Share Posted August 31, 2008 I still don't see the need for 2 tables. Are the four photos for the credit page supposed to be the last four that have been uploaded? If so, then just create a query that selects the last four from the gallery table. If not, then just create a new column in the gallery table called 'credit' (or something similar) and set the value to true for the four photos from each contributer that will be used for their credit display. Quote Link to comment Share on other sites More sharing options...
dropfaith Posted August 31, 2008 Author Share Posted August 31, 2008 yeah i want the 4 photos to be the last 4 uploaded with the photographer named in the credit box.so it would need tp update that database if the photographer already exists. Quote Link to comment Share on other sites More sharing options...
dropfaith Posted August 31, 2008 Author Share Posted August 31, 2008 bump Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 1, 2008 Share Posted September 1, 2008 As I said, you don't need a 2nd table. Simply use the gallery table. Since you will probably need to query the top four photos for all photographers at the same time, I would probably include an 'timestamp' AND a 'credit' column. The credit column would be a simple true/false value and the last four for each photographer would be set to true. You would first want a procedure to follow when new photos are uploaded to ensure only the last four photos are set to true. Here is one example: //Insert new photo $query = "INSERT INTO gallery (photo_name, timestamp, user_id) VALUES ('$name', $timestamp; $u_id)"; $result = mysql_query($query); //Reset all current 'credit' values $query = "UPDATE gallery SET credit=false WHERE user_id=$u_id AND credit=true"; $result = mysql_query($query); //Get the top 4 for the user $query = "SELECT id FROM gallery WHERE user_id=$u_id ORDER BY timestamp LIMIT 4"; $result = mysql_query($query); while($record = mysql_fetch_assoc($result)} { $photo_ids[] = $record['id']; } //Set the top 4 for the user to true for the credit column $query = "UPDATE gallery SET credit=true WHERE id IN (" . implode(',', $photo_ids) . ")"; $result = mysql_query($query); You can then get all ofthe top four photos for all photographers with this SELECT * FROM gallery WHERE credit=true 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.