1

Im wondering if someone could help me out with a little issue im having.

I have some code which enables a user to click a button and it will create a additional file input box ... The amount of times they can click this is unlimited, so realisticly they can add unlimited images to their profile.

The problem im having is im not sure how to go about saving that information to the database, usually i would add a row for a file input and store the name, but as there can be unlimited amounts of filenames, im not sure how i would go about saving it.

Could anyone out there give me some suggestions on how they would do it?

Thanks

0

2 Answers 2

3

I would store additional pieces of information in a separate table. It only needs 2 fields, data and user_id, Then for each additional input, you would store the data and the user's unique user_id. To retrieve the data, just filter using the user_id.

Sign up to request clarification or add additional context in comments.

6 Comments

Except for it is nearly always better to have primary key, so add auto_increment id if you are planning to refer to that images individually.
True, but this was stripped down to the heart of the issue.
Hmmm thats an interesting way of tackling it .... What about serializing it and putting it in a field on teh same row as the details?
@BigJobbies the problem with serializing it is that, as you mentioned, you don't know how many extra input items there are. You really don't want to run out of space trying to cram it in one field. Also, it is more efficient to let the dbms fetch the data, than to have a program sort it out.
Agreed with @BigJobbles, sometimes I used exactly that way he described in comment. For example, to store filenames of multiple thumbnails or previews.
|
0

Usually it's doing using 2 tables and foreign keys. One table with users(user) (id, name, ...). Second table with photos of users(user_photo) (id, user_id, photo_path, ...). Foreign key will be created between user.id and user_photo.user_id with cascade delete/update.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.