0

New to PHP and need some help with this.

I'm creating a test, but I'm getting all of my questions randomly from my database.

For example, if this is my table:

ID S Q1 A1 A2
1 C Why A B
2 F When A B

I know that I need the query to select from Q1, A1 and A2, leaving the rest out, but I'm not sure how I can get that into a form.

Thanks for your help!

3
Contributors
7
Replies
9
Views
6 Years
Discussion Span
Last Post by P0lT10n
0

You must first request this data like this

$query = mysql_query("SELECT Q1, A1, A2 FROM --YOUR_TABLE--");
while($row = mysql_fetch_assoc($query)){
    echo $row['Q1']."-".$row['A1']."-".$row['A2'];
}

Edited by P0lT10n: n/a

0

Thank you so much, the data requested perfect!

When I'm pulling the data to put into a form with radio buttons, am I doing that in html and pulling the options and questions from the $query?

Really lost on what to do next. Your help is greatly appreciated.

0

Thank you so much, the data requested perfect!

When I'm pulling the data to put into a form with radio buttons, am I doing that in html and pulling the options and questions from the $query?

Really lost on what to do next. Your help is greatly appreciated.

I dont understand what you need !

0

Im gonna give you an example based on the code you gave me. I want a form to have the question first and then the answers with radio buttons.

In my form:
I want Q1 to be the question
I want A1 to be the first option with radio buttons
I want A2 to be the second option with a radio button

I'm just having a hard time flipping from HTML back to PHP and getting it to connect.

0

Thanks,

I finally have what I want, I hope. Here's the code I used.

$res = mysql_query("SELECT question_no, question, answer_a, answer_b, answer_c, answer_d, answer_e FROM t_questions");
echo "<form name='whatever' action='next.php' method='get'>";
while($row = mysql_fetch_assoc($res))
{
    echo $row['question'] . '<br />';
    echo "<input type='radio' name='choice' value='" . $row['question_no'] . "' /> ". $row['answer_a']. '<br />' ;
    echo "<input type='radio' name='choice' value='" . $row['question_no'] . "' /> ". $row['answer_b']. '<br />' ;
    echo "<input type='radio' name='choice' value='" . $row['question_no'] . "' /> ". $row['answer_c']. '<br />' ;
    echo "<input type='radio' name='choice' value='" . $row['question_no'] . "' /> ". $row['answer_d']. '<br />' ;

Edited by pyTony: fixed formatting

0

But if you use as value the question number or question_no, and the user select any answer, you will get the same value, and you wont know what answer was... Mark thread as solved please !

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.