954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

mysql select coding for form to be submitted

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!

cleecaldwell
Newbie Poster
4 posts since Jul 2011
Reputation Points: 10
Solved Threads: 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'];
}
P0lT10n
Posting Whiz in Training
235 posts since Apr 2010
Reputation Points: 13
Solved Threads: 30
 

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.

cleecaldwell
Newbie Poster
4 posts since Jul 2011
Reputation Points: 10
Solved Threads: 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 !

P0lT10n
Posting Whiz in Training
235 posts since Apr 2010
Reputation Points: 13
Solved Threads: 30
 

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.

cleecaldwell
Newbie Poster
4 posts since Jul 2011
Reputation Points: 10
Solved Threads: 0
 
Gel
Newbie Poster
19 posts since Dec 2006
Reputation Points: 14
Solved Threads: 3
 

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 "";
while($row = mysql_fetch_assoc($res))
{
echo $row['question'] . '
';
echo " ". $row['answer_a']. '
' ;
echo " ". $row['answer_b']. '
' ;
echo " ". $row['answer_c']. '
' ;
echo " ". $row['answer_d']. '
' ;

cleecaldwell
Newbie Poster
4 posts since Jul 2011
Reputation Points: 10
Solved Threads: 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 !

P0lT10n
Posting Whiz in Training
235 posts since Apr 2010
Reputation Points: 13
Solved Threads: 30
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: