Page 1 of 1
Uploading a certain amount of pictures
Posted: Wed Jul 17, 2002 10:45 am
by chris12295
I have a MySQL table of picture url's that users can upload and asscociate with an online ad. I need to only let them associate 4 picures and if they upload another replace the first then second and so on....
Any help doing this would be greatly appreciated.
Picture TABLE:
id
adID
userID
src
Ad table:
adID
userID
...
Steps to take
Posted: Tue Jul 23, 2002 4:14 pm
by musashi
I responded to another question on image file uploads, so you can check that out if you would like information on how to let users upload a file and how to store that file as a file on the server or as source in a mysql db.
Assuming you already know that part... here are the logic steps I see in your program. (Starting from, file has been uploaded)
1. Check user information in db.
2. If user has 4 files in db, delete first file
3. Insert new file
Since mySQL maintains a FIFO ordering, you can eliminate the files in the order they are retrieved. So it might look something like this:
$result = mysql_query("
SELECT * FROM TABLE
WHERE user_id=$user_id"
,$dblink);
if(mysql_num_rows($result) >= 4) { //should never be greater than 4
$deleteMe = mysql_fetch_object($result);
mysql_query("
DELETE FROM TABLE
WHERE id = $deleteMe->id"
,$dblink);
}
//I assume "id" is an auto_incremented primary key, so each value should
//be unique.
mysql_query("
INSERT INTO TABLE (adID,userID,src)
VALUES ($adID,
$userID,
$src)
,$dblink);
If you want the "src" field to contain the actual picture data (you can see this in the other posting) remember to set it as a binary field type (blob, mediumblob, etc.)