I am trying to create an application like Facebook in which each user can create multiple albums and then place photos inside it. Users can also comment on the photos, so I need to make a database where album_name, pic_name, then comments on the pic will be applied.
I have a concept but I don’t know whether it is feasible or not.
Here is my user table schema:
candidate_register_table
|----------------------------------------------------|
| username | name | age | sex | password |
|----------------------------------------------------|
A record would look like this:
|---------------------------------------------------------|
| saz26 | Saswat Routroy | 26 | Male | Saswat |
|---------------------------------------------------------|
Now I want to create a table holding the album_names for each user creating albums.
Say the table name is saz26_albums, where saz26 is the username in the candidate_register_table, (I am concatenating the username with the string "_albumname" to create a table) the schema of this table will be like this:
|------------------------------|
| album_name | cover_pic |
|------------------------------|
A tuple in the above table will look like this:
|--------------------------------------------------------------------------|
| Candidate_Pics/Male/saz26/MyPics |Candidate_Pics/Male/saz26/MyPics/2.jpg|
|--------------------------------------------------------------------------|
That means, for each username, a new table username_albums will be created holding the path of each albums(folder) he creates:
Another table with the name saz26_pics will be created with the following schema:
|------------------------------------------|
| pic_name | album_name | caption |
|------------------------------------------|
For example like this:
|------------------------------------------|-----------------------------------|----------|
| Candidate_Pics/Male/saz26/MyPics/1.jpeg | Candidate_Pics/Male/saz26/MyPics | At Sea |
|------------------------------------------|-----------------------------------|----------|
Now, the last part, which definitely needs a table for each picture, I mean that a table denoting a single pic, and it contains all the usernames, and their corresponding comments given by them.
Say for example, a table with name:
saz26_MyPics/1_comments
|----------------------------|
| username | comments |
|----------------------------|
For example like this:
|----------------------------------|
| suhani18 | Where is this place |
|----------------------------------|
| saz26 | Dead Sea |
|----------------------------------|
I don’t know whether any other possible design can be achieved, I just want someone to let me know any other possibilities. If any other possibilities not present, then is my design feasible enough?
Some people told me to maintain a schema somewhat like this by creating a table albums:
|-----------------------------------------|
| username | album_name | cover_pic |
|-----------------------------------------|
This doesn’t solve my problem which is how to maintain comments on each picture. Because some pictures can have 200 comments, some 3 comments and some will have no comments at all.
You only need four tables:
users,albums,picsandcomments. Each table should have anidcolumn of typeint, withauto_increment, and set as the primary key for the table.Then on table
albumsyou have auser_idcolumn for the album owner. Onpics, you have analbum_id, and oncommentsyou have bothpic_idanduser_id(allintcolumns, preferably indexed).With such a structure, you can easily retrieve you data using SQL JOINS.
UPDATE
Since
usernameis already a PK on the users table, you can use that instead ofuser_idinalbumsandcomments.About the comments table: it seems to me that it only needs 3 columns:
username(the user who made the comment),pic_id(the id of the picture the comment refers to), andcomment(the comment itself).