I’ll try to illustrate what I mean with an example.
Say you are running a site that has users and allows posts.
You have a list of users and each user has:
a name
a password
choice of theme
POSTS:
– title of post
– time/date of posting
– post ID
– array of tags for the post
User ID/name/pass/theme is easy. Each variable can be a column, ID auto-incs. When I get to the posts I’m not sure what to do. In nice friendly OOP I would just make a post object type and make an array of those for the user. How am I supposed to do this in the mySQL DB? I was sort of shocked that it wasn’t one of the 1st things in my textbook, this has to be pretty damn common. Anyways, I could probably make a horribly ugly hack to get it to work but I’d like to know the ‘correct’ way.
Thanks!
Members:
Posts:
Tags:
Tag_Relations:
Posts is your “array” of posts, with the member_id column linking each post to its user.
Tags is your “array” of tags, Tag Relations links each tag to one or more posts.
Here is an example of how you could get all posts & tags for a user with one query: