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 7185573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:26:44+00:00 2026-05-28T18:26:44+00:00

I have two table named: Blog for displaying blogs post and comments for displaying

  • 0

I have two table named: Blog for displaying blogs post and comments for displaying comments section for each blog post.

The fields for these are as follows:

For Blog:

1: blog_id

2: title

3: body

4: author

5: updated

For Comments:

1: comments_id

2: name

3: email

4: body

5: blog_id

The field blog_id must be the same for both the table.

Now what i want is that suppose for blog_id = “2”, I am writing comment, so what would be the insert query so that when i visit index.php?blog_id=2, I get the comments for only that particular post.

I mean how to insert the comments for a particular blog_id?

I tried this query to insert:

INSERT INTO cms.comments(blog_id, name,email,comments_body)
                VALUES (
                    '".$arr['blog_id']."',
                    '".$arr['name']."',

                    '".$arr['email']."',
                    '".$arr['body']."'
                ) );
  • 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-28T18:26:45+00:00Added an answer on May 28, 2026 at 6:26 pm

    Ok, I have done it myself [NO need to implement foreign key].

    Here is the solutions.

    The requirement was that the field “blog_id” of comments must be equal to “blog_id” of blog

    This can be done in the following manner. First get the blog’s “blog_id” by the following statement…

    $sql = "SELECT * from blog WHERE blog_id = '$blog_id'";
    $res = mysql_query($sql) or die(mysql_error());
    $row = mysql_fetch_assoc($res);
    $iItemId = (int)$_POST['blog_id']; // obtaining necessary information
    

    The using INSERT statement like this, insert it…

    mysql_query("INSERT INTO amityadav.comments(blog_id, name,url,email,body)
                    VALUES (
                        '$iItemId',   //This variable is from the blog_posts' "blog_id" which will be inserted into the comment's "blog_id"
                        '".$arr['name']."',
                        '".$arr['url']."',
                        '".$arr['email']."',
                        '".$arr['body']."'
                    )");
    

    Now in order to retrieve it use the flowing query…

    $sql = "SELECT * from blog WHERE blog_id = '$blog_id'";
    $res = mysql_query($sql) or die(mysql_error());
    $row = mysql_fetch_assoc($res);
    $iItemId = (int)$_GET['blog_id']; // obtaining necessary information
    $comments = array();
    $result = mysql_query("SELECT * FROM comments WHERE `blog_id` = '{$iItemId}' ORDER BY comments.id ASC ");
    

    Using these queries, I have successfully implemented what I wanted…:)

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

Sidebar

Related Questions

I have two tables as following table one named tbooking having column fields as
Say you have a Table named Sales with a SalesOrderId. Then you have two
I have two table in mysql named rootpath with only one field 'root' and
Hi have a table named category which has two foreign keys to the table
I have two tables. The name table have a foreign key named 'categories'. The
I have two columns named FirstName and LastName. I want to query these from
I have a LinkTable named: BlogsBlogPosts that relates two other tables named: Blogs and
You have two tables named Customer and SalesOrder. In the Customer table you have
I have table named collections in which there are fields pk_collectionid and name .
I have a blog-style app that allows users to tag each post with topics.

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.