Page 1 of 1

user login with blog... relatively new to php... questions

Posted: Sat Jun 09, 2007 10:57 am
by suthie
I am trying to make a blog type thing with user login. I know how to make a user login system with PHP and MySQL... but what i want to do is more complicated.

each user will need variables for username, passsword, and email.
each user will have multiple blog sections (public and private blogs) and other profile areas to update

my question is this:

(with MySQL) can i fit all those variables into a row for each user? or should each user get his own table?

Posted: Sat Jun 09, 2007 11:04 am
by Luke
a table for each user would not be good. I know that much for sure. As for what tables you WILL need, it's hard to say without a better description of what you're trying to do. When you say each will have multiple blog sections, what exactly do you mean. Describe your ideal system in detail. Also, I'm moving this to databases. :arrow:

Posted: Sat Jun 09, 2007 11:10 am
by suthie
thanks for the reply!

here's what i want to do (in more detail)

i am making an online journal to give students a place to write down their thoughts. each student will have a username, password, email address, and optional picture. they will also have the option of linking to their four favorite user's blogs.

when i say multiple blogs i mean this: they will have a public one and a private one.

there will probably be about two or three other profile variables later on.

does that make sense?

Posted: Sat Jun 09, 2007 11:26 am
by bdlang
Based on your general outline I'd suggest at least three tables: `users`, `blogs`, `user_blogs`.

`users` is only concerned with user data: `userID` (INT PK), `username`, `password`, `email`, `picture`, other user stats
`blogs` is only concerned with blog information: `blogID` (INT PK), `blogTitle`, `blogContent`, other blog info
`user_blogs` links the two: `userID` (INT FK), `blogID` (INT FK), `isPrivate` BOOL

A fourth table to store the links would be a good idea, either linked by userID or blogID (or a composite of both).

Posted: Sat Jun 09, 2007 11:30 am
by suthie
would it work to make the four links in the first table? like maybe have columns:

userid, username, password, email, picture, link1, link2, link3, link4

(if all the links are just usernames, not urls)

also, i understand how the first two tables would work i think. but the third one im not so sure... can you give me an example of what it might look like? or maybe give me a little more detail of what you mean?

thanks

Posted: Sat Jun 09, 2007 11:40 am
by Luke
OK, so what I'd do is have at least three tables (this would allow you not to have to duplicate any information in your database)

users
id
username
password
fname
lname
etc. (other standard user info such as description, etc.)

blogs
id
name
description
access (public or private)

posts
id
blog_id (relates to the id of the blog this was posted in)
user_id (relates to the id of the user who posted this)
title
postbody

Or, if you know for sure you aren't going to ever need more than a public and private blog, you could eliminate one of the tables

users
id
username
password
fname
lname
etc. (other standard user info such as description, etc.)

posts
id
user_id
access (1 for public 0 for private)
title
postbody

But the first is a lot more flexible

Posted: Sat Jun 09, 2007 11:53 am
by suthie
thank you! that makes so much sense! :D


I think i can totally do this now!

my only remaining question is how can i link a post to a post, like a reply to a post?