Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Databases

Steve Meadows
seal-mask
.a{fill-rule:evenodd;}techdegree
Steve Meadows
Full Stack JavaScript Techdegree Student 15,218 Points

multiple users completing a task from one database

Hi Everyone, I was wondering if those that are good with mysql and php could please help me with this. I have a file that i require everyone to read from my database when they login.. this is simple to do as I can fetch the data, but where it comes tricky i want them to be able to complete the task but only for that individual user so that it remains incomplete for the others. I also want to be able to upload more files for them to do the same with. does anyone know how is best to structure my database, should i user alter table when uploading and add the individual uploads to everyone to complete on their own?

Sorry to ask this here but i am trying to get to grasp with databases and cant seem to solve this one so please any help would be appreciated.

3 Answers

Steven Parker
Steven Parker
231,248 Points

It sounds like every user needs to have a unique ID, and the table(s) that they are referencing should have an ID column. This would make both the coding and storage more efficient than keeping separate tables for each user.

Then you can design your queries to use the ID as a filter criterion (in a "WHERE") so that each user's work will not be affected by any other's.

For example, if your documents table contained: id|username|file_name|ref|uploaded_on|status, you could build a query to return only the current user's document info like this:

var SQLcmd = `SELECT * from documents WHERE username = ${logged_in_user}`;

The exact syntax would of course vary based on what language you are developing with.

Steve Meadows
seal-mask
.a{fill-rule:evenodd;}techdegree
Steve Meadows
Full Stack JavaScript Techdegree Student 15,218 Points

Thank you for your reply Steven. How would i go about this.. sorry i am new to MYSQL so hope you don't mind all the questions.

Would i do a table for each user? My user table at the moment is as follows: id(int) ¦ username ¦ password ¦ email ¦ role_id

and my documents table is: id(int) ¦ file_name ¦ ref ¦ uploaded_on ¦ status

I am sorry to be a pain but i am at my wits end trying to get this to work and any help is really appreciated.. do i just add a unique id to each table or do i need to create a new table? with the where statement also would this be the unique id with a question mark after it for the person who is logged in?

Sorry i am very confused.. this is kind of beyond my skillset at the moment but i am hoping to learn more and more and grow at this so thank you for your time with this.

Many Thanks

Steve