Displaying data from a mysql table in php

I have a php form that asks a question and when submitted will store the question in a MySql table called ‘questions’.
I have another php form where an answer can be posted to that question and is stored in same table as the question.
How would I display all of the questions - those with answers and those without answers on a seperate page where the answer is beneath the question.

In the table I have the folowing fields
id,
question,
reply

Below is an example of how I would like the display to look. Some questions may not have answers while others will.

example:
Q1: How big is the car?
Q1Answer: It is 5 meters from bumper to bumper.

Q2: What color is the dog?

Q3 Will it rain today?
Q3Answer: Only if there are clouds in the sky.

Q4: Who is on first?

Q5: What time is it?

Q6: Do you have ice cream?
Q6Answer: We have chocolate and vanillia.

I have a basic idea on how to do this but am not sure of how to write the code for it. The idea would go something like this:

Check database for questions
—if there are questions
------print question
--------check database for answer to question
-----------if question has answer
-------------print answer
-----------else print blank line
—else print blank line
next check

If someone could give me hand writing the php for this I would be eternally indebted to them. (I’m a poor fellow and am already eternally in debt to many not the least of which is the bank LoL, but you will also have my eternal gratitude too. :slight_smile: )

Hi Montey and welcome to SitePoint,

The php docs have all the answers you need for writing MySQL queries using PHP, plus Google has thousands of results at hand which are very helpful too.

http://php.net/manual/en/book.mysql.php - MySQL (Procedural only)
http://www.php.net/manual/en/book.mysqli.php - MySQLi (Procedural and OOP)
http://php.net/manual/en/book.pdo.php - (Recommended)