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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:22:37+00:00 2026-05-18T00:22:37+00:00

I have two tables in a database. Table questions , has two columns, ID

  • 0

I have two tables in a database. Tablequestions, has two columns,ID and question. Table two answers has two columns question_ID and answer. In table answers there more than one answer pertaining to a question. So there are duplicate question_IDs. How do i display all questions from table questions with all the answers pertaining to it from table answers right under the question? Like:

How far is the sun?

The sun is 18 million miles away.
The sun is 93 million miles away.
The sun is 2 miles away.

How big is the sun?

Big.
Small.
Medium.

etc…

Sorry if the question seems a bit vague but its the best way i can explain it. Thanks in advance.

  • 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-18T00:22:38+00:00Added an answer on May 18, 2026 at 12:22 am

    You would execute a select query that joins the two tables, ordering by the question id.

    SELECT q.ID as question_id, q.question, a.ID as answer_id, a.answer
    FROM questions q
    LEFT JOIN answers a ON a.question_ID = q.ID
    ORDER BY q.ID, a.ID
    

    This will give you a result set like:

    question_id   question                 answer_id   answer
    1             What color is the sky?   100         Blue
    1             What color is the sky?   101         Red
    2             How old is dirt          102         Very Old
    2             How old is dirt          103         Kinda Old
    

    etc

    When you loop through this result set you need to keep track of what the last question was so that when you go to the third result, question 2, you know to display the next question.

    e.g.

    $PreviousQid = null;
    foreach ($QueryResult as $QueryRow)
    {
       if ($PreviousQid === null || $PreviousQid != $QueryRow['question_id'])
       {
           echo "<b>" . $QueryRow['question'] . "</b><br/>\n";
       }
    
       echo $QueryRow['answer'] . "</br>\n";
    
       $PreviousQid = $QueryRow['question_id'];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables in my database: NEWS table with columns: id - the
I have a MySQL database with two tables (simplified for this question): movies table
I have two simple tables in my database. A card table that contains Id,
I have a simple database with two tables. Users and Configurations. A user has
Excuse the long question! We have two database tables, e.g. Car and Wheel. They
Background: I have a database table which is for received_msgs The table has two
I have two tables in my database, called ratings and movies . Ratings: |
Suppose I have a database table with two fields, foo and bar. Neither of
Let's say I have two tables: Report Comment And assuming I have a database
Here is a simplified version of my database model. I have two tables: Image,

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.