Solved

How to set up mysql database to hold multiple image path fields

Posted on 2007-11-26
5
692 Views
Last Modified: 2011-09-20
I've currently got a script which uploads one image to my server and stores the path to that image in my database.
However I want the user to be able to upload more than 1 image at a time (probably around 12). Now in php I can easily upload multiple images using a loop, that's not the problem.
My problem is how do I store the paths to all uploaded images in my database?
Would I have to add more path fields? (like path1, path2, path3 etc.)

Currently my image table cosists of ID, Name, Path fields.

Can anyone shed some light on this please? it's been bugging me for too long.
0
Comment
Question by:thephiller
  • 3
  • 2
5 Comments
 
LVL 7

Expert Comment

by:bdichiara
ID: 20353932
I would suggest associating these images in groups or albums (like with GroupID or AlbumID). Then you can have multiple records in your table all grouped together. Then give the group some meaningful title or link that to an album or whatever.
0
 

Author Comment

by:thephiller
ID: 20354012
The images is associated with an album table so I'm using one table to store the album details and one table to store the images and image details.

I'm more after how I can technically achieve this since I'm kind of lost at the moment.
0
 
LVL 7

Expert Comment

by:bdichiara
ID: 20354280
Well, I don't know what your code looks like, but when you loop through the uploads, insert each one as a record into the image table. and just set the album id to be the same for the entire upload.
0
 

Author Comment

by:thephiller
ID: 20356831
How would I go about setting the id for the entire upload?

Now when it goes through the upload script it adds to the image table:
ID
NAME
PATH

My problem (sorry, if I'm having a bit of a hard time understanding this) is how I store the individual images. Would I have to add more path fields?
Like:

ID
NAME1
PATH1
NAME2
PATH2

Or do you suggest I DON'T make the id field in the image table auto increment but assign the id myself?
Sorry, I'm still a little lost.
0
 
LVL 7

Accepted Solution

by:
bdichiara earned 500 total points
ID: 20362700
The ID in the table mentioned above is the ID for the individual image, correct? You should have:
ID - int - auto_increment
NAME - varchar
PATH - varchar
ALBUM - int

Then in a separate table
ALBUM_ID - int - auto_increment
DESCRIPTION - varchar

Then you either create a new album (using auto-increment, and get the ID with mysql_insert_id) or you can have the user select an existing album.

Use this ALBUM ID and put in all instances of ALBUM for that upload.

So in plain terms:

If(new_album?){
    INSERT 1 row into ALBUMS
    $ALBUM_ID = mysql_insert_id(); (php function)
} else {
    $album_id = USER selected album.
}

upload_loop {
   DO File placement stuff...
   INSERT file path, name, album_id into IMAGES table
   (you get the album_id from above)
}

Does that make better sense?
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
tutorial for ebay api 3 35
mysql date time 14 32
MySQL Memory Keeps Increasing 4 37
I've got an interview this morning and I want to sound intelligent... 4 54
These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question