Solved

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

Posted on 2007-11-26
5
691 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
php date - compare 4 40
PHP7 and Sql Server Windows 2008 R2 13 85
join tables 4 50
RELATED: How do I fix this error:  Warning: strpos(): Empty needle on line 122 11 32
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

914 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now