Jump to content

Inserts


dropfaith

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

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.