Jump to content

How should I go about making this?


Recommended Posts

Well, I'm trying to make a News System, with PHP and MySQL, and theres a button where you can click to go to comment on the News Post, such as Cute News.In my table, called news, so far I have the columnstitle - Title of the News postnews - The actual newsposter - Who posted itid - The id number of the post.For each post submitted, a new row is made. Not, if I were to make a Comment System, I would also need to store the comments, for each News post.How can I set up my table for this?Oh, if this is meant to be in the SQL Forum, please say so.Thanks, Mememe.

Link to post
Share on other sites

Create a new table Comments, in it put:title - Comment TitlenewsID - Use the ID from for the news article they are commenting on.poster - Who added the commentcomment - The actual comment..id - The comment IDThen just use the same method for printing the news and on the news page also print the comments where newsID in the comments field is the same id in the news field...

Link to post
Share on other sites

You may want to add a time field, and I wouldn't recommend capital letters in anything rswildy, unless you are doing everything like that.But yeah, rswildy has the idea for the most part, and you would just select comments where newsid == (news table) id.

Link to post
Share on other sites

Well, if you start working on group projects and such it starts to matter a whole lot. Normally people advocate against capitals in coding standards, but I guess it's just a choice. Lets try not to get too off topic eh?

Link to post
Share on other sites

Alright, I'm trying to make something similar to CuteNews. Currently, my table has the columnstitle, for the title of the newsnews, the actual newsid, which is the id of the postposter, the person who made the postEverytime a new post is made, a new row is added to it. When the page, news.php is displayed, it gets the data from this table. Now, I have a page called newscomment.php On this page, there are forms for people to post comments. Now, how would I make it so that I can implement the comments, into each row, since each row will have it's own set of comments.

Link to post
Share on other sites

i guess you need to have at least three tablesnews commentposternews -> news_id | news_content | etccomment-> c_id | c_news_id | poster_idposter > poster_id | etc...so you will haveposter_id+---<news_id but since i made a crossing table all the data will base in the comment table and redundancy will be avoid

Link to post
Share on other sites

What I thought was to have an max number of comments. Say the max number of coments per News post is 5, I could have the columns:comment1comment2comment3comment4comment5But I don't want a max.

Link to post
Share on other sites

You don't need to, teng84 is advocating a one-to-many relationship for your system, in a

			   |-comment		|-news-|-comment		|	  |-comment		|		|	  |-comment		|	  |-comment		|-news-|-comment		|	  |-commentPoster -|	  |-comment		|		|	  |-comment		|-news-|-comment			   |-comment

kind of way.The idea is that you have a table for posters, a table for news and a table for comments, all with primary keys. When a poster posts, their id is entered into the poster field of the news table, and when someone makes a comment, the news item that they are making it for's id goes in the news_id field of the comments table. That means that when someone adds a new post item, the system just adds another row to the comments table.

Link to post
Share on other sites
You don't need to, teng84 is advocating a one-to-many relationship for your system, in a
			   |-comment		|-news-|-comment		|	  |-comment		|		|	  |-comment		|	  |-comment		|-news-|-comment		|	  |-commentPoster -|	  |-comment		|		|	  |-comment		|-news-|-comment			   |-comment

kind of way.The idea is that you have a table for posters, a table for news and a table for comments, all with primary keys. When a poster posts, their id is entered into the poster field of the news table, and when someone makes a comment, the news item that they are making it for's id goes in the news_id field of the comments table. That means that when someone adds a new post item, the system just adds another row to the comments table.

Oh, I get it now. So I have 2 tables, the normal table, which is the news table, and another called comments.On the comments table, I have the 2 columns, post and news_id. The post is the actually post itself, and the news_id is the id which the comment to connected to. Is that sort of what you mean?
Link to post
Share on other sites
Oh, I get it now. So I have 2 tables, the normal table, which is the news table, and another called comments.On the comments table, I have the 2 columns, post and news_id. The post is the actually post itself, and the news_id is the id which the comment to connected to. Is that sort of what you mean?
That's exactly what he means and that's exactly the feature which makes databases useful - associating one data (the comment in this case) with another data (the news in this case), thus giving you the possiblity to have a page that uses one data (the news) and it's proper connections (all comments, but only those associated with that news item).
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...