Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7038713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:42:08+00:00 2026-05-28T01:42:08+00:00

I’ve read several tutorials, documentations about mysql, db structures and also I’m using it

  • 0

I’ve read several tutorials, documentations about mysql, db structures and also I’m using it via php for weeks. Now I get a problem, I don’t know how to form/organize/create my db structure for posts and comments. I’ve already read some posts about this (here on stackoverflow), but I didn’t find anything useful. I understand that I need to have 2 tables for posts and comments, and when I need to print them on the page with a foreign key (or ID) I “merge” them (only on the page, not with SQL). When a person is viewing the page, he is seeing the post and comments normally, but in the “background” everything is stored in 2 tables.

Am I needing to add a new column every time when somebody is adding a new comment or a reply?

If my question is true, that means if in a post are 100+ comments, that means I need to ALTER the TABLE every single time? That means if post “A” has 3 comments and post “B” has 150 comments, my table “comments” will have 100+ columns?

E.g:

Posts | column1 | column2 | … | columnN

A | bla1 | bla2 | bla3 | – empty | – empty | … | – empty – |

B | bla1 | bal2 | bla3 | bla4 | bla5 | bla6 | … | bla100 |

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:42:08+00:00Added an answer on May 28, 2026 at 1:42 am

    At a basic level, you would have a table for each type of “thing” in your application. In this case, a table for Posts and a table for Comments. Something as simple as this:

    Post
    --------
    Id
    Content
    User
    DatePosted
    
    Comment
    --------
    Id
    PostId
    Content
    User
    DatePosted
    

    This would create what’s called a one-to-many (or zero-to-many, actually) relationship between Posts and Comments, whereby each Post can have zero or more associated Pomments but each Comment can be associated with only one Post.

    In your code (which is a whole other subject entirely), to display a Post and its associated Comments there are a couple of things you could do. Assuming you have, as input, the Id of the Post you want, you can get that Post and its Comments:

    SELECT `Content`, `User`, `DatePosted` FROM `Post` WHERE `Id` = ?Id
    SELECT `Id`, `Content`, `User`, `DatePosted` FROM `Comment` WHERE `PostId` = ?Id
    

    What you do with that resulting data is up to you and how you want to use it in your application. It would come back as two table results, the former of which has one record (if the Post exists) and the latter of which has zero or more records. Naturally, you’ll want to check that things exist before trying to use them, etc. (So if the first query returns no results, don’t try to continue to display the Post. Just show a default response or an error.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I have a jquery bug and I've been looking for hours now, I can't
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.