Jump to content

Archived

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

digitalgod

Inserting data in a field only if that field is empty

Recommended Posts

Hey guys,

I've made myself a image upload script that limits each users to a maximum of 10 images. What I'm trying to do is have the names of those images written in a table.

Now I'm not sure what's the best way to make a table for this. What I've done is I added 21 fields in my users table, 1 for main_thumb and the rest for img1, img2, etc status1,status2 etc

the status fields are for whether the admin approved or not the images.

My problem is that when a user uploads an image I want the script to be able to find out where to insert the name so if the user already uploaded 1 image and is uploading a second one the script will see that that the img1 field has something in it but the img2 field is empty so it will insert the name in img2 and insert "Pending Approval" in status2.

I hope I made myself clear!
Any help would be greatly appreciated

Share this post


Link to post
Share on other sites
I have a program with a simular issue, only it's with adding new part numbers to the system:

Here is how I did it:

I great big script!

first run a query starting with the lowest field number and do a series of clauses until I find an "empty". if there is not "empty", then they get an error message...

You just have to think very linear to figure it out, but it's not that hard.

Share this post


Link to post
Share on other sites
[!--quoteo(post=361649:date=Apr 4 2006, 02:32 PM:name=AV1611)--][div class=\'quotetop\']QUOTE(AV1611 @ Apr 4 2006, 02:32 PM) [snapback]361649[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I have a program with a simular issue, only it's with adding new part numbers to the system:

Here is how I did it:

I great big script!

first run a query starting with the lowest field number and do a series of clauses until I find an "empty". if there is not "empty", then they get an error message...

You just have to think very linear to figure it out, but it's not that hard.
[/quote]

thanks for your reply AV1611 but I think I have it all wrong.

I think it would be much easier if I created a table for the images something like

id || username || image_name || status

that way there won't be as much clutter as before plus there won't be a problem when people start deleting and adding new pics.

Now my question is would a table like that be any good or will it slow things down since the script might have to do a lot of searching to find the images that belongs to a user. And what will happen if a user deletes an image and the whole row is deleted, will the id change by itself or will it remain the same?

example:

id || username || image_name || status

342 || AV1611 || 123.jpg || Approved
343 || digitalgod || 456.jpg || Approved

and you decide to delete your 123.jpg what will happen if I remove the whole row?

Share this post


Link to post
Share on other sites

×

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.