Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2007-11-26
5
Medium Priority
?
705 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 2000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

877 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