Solved

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

Posted on 2007-11-26
5
695 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Node.js 11 82
Do not understand error message 3 46
How can I get these two for loops to talk to one another politely? 6 51
How can I split a variable 19 46
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

752 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