Jump to content

Inserting data in a field only if that field is empty


digitalgod

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
Link to comment
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.
Link to comment
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?
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.