0

I am still quite new to mysql and I was curious what the best way to go about saving multiple-users' information in a database. I apologize for this question being as clueless as it is, but I have not been able to find any sort of examples or tutorials regarding this subject.

For example, if there are multiple users and they want to log the distance they have ran and then be able to access this information later, can I store their information in some sort of multi-dimensional array which is linked to their username? Is there a way to do this using cookies? Can cookies be stored on the server and then retrieved on a different computer when the user logs in? Or is it as simple as creating a new table for the user and then storing all of the information there?

Any direction you could offer me would be appreciated

1
  • 1
    simplest method: extra column in your data table that says which user owns that record. Commented Aug 13, 2012 at 0:39

1 Answer 1

3

You need multiple tables:

User Table:

  • ID (Auto increment)
  • Name (varchar)
  • ...more info...
  • ...more info...
  • etc...

Distance Table:

  • ID (auto increment)
  • User_id (Int)
  • Distance Ran (varchar)
  • ...more info about the trip...

Now, you can do something like this to get all the runs by a certain user:

SELECT * FROM users LEFT JOIN distance ON users.id = distance.user_id WHERE users.id = $user_id

where $user_id is the person's ID. This will give you all the runs that the user did along with their user information

Good luck! Please ask if you have more questions.

P.S. If you plan to keep data for more than a couple hours, you don't want to use COOKIES or _$SESSION vars, because they are prone to expire, and won't be available to users that login from multiple endpoints.

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

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.