Jump to content

form with information from database


cleecaldwell

Recommended Posts

Hi everybody, hope someone can help out with this.

 

I've been taking online courses for php, while working a new project for myself. Here's what I want to do.

 

I want create a test with random questions that are generated from my database. In this form I would like to submit the results for a grade and send the results to myself and add to my database. I have no idea where to start. I see where I can add information to a database, but I don't see how I would get information from a database randomly.

 

Any help would be greatly appreciate or a push in the right direction.

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/243370-form-with-information-from-database/
Share on other sites

Table call question and answer

 

Id Q A

1 Q1 A1

2 Q2 A2

 

USE RAND

$randomstring .= mt_rand(1,2);

QUERY THE TABLE

SELECT  * FROM  q&a Where  id=$randomstring;

Echo the result.

Input answer -> $_post[‘answer’];

 

If ($_post[‘answer’] == $row[‘A’])

{    Answer OK! }

Else

{ Answer Wrong! }

 

 

So what if my table looked liked this based on your code.

 

ID    Q      A      S

1      Q1    A2    S1

2      Q2    A3    S2

 

What if I only wanted to select from ID, Q, and A. and not S.

 

Also, I'm not getting how to make the form select from the database...

I finally have the information that can be pulled from the database.

 

When I echo the $row into the form do I use html?

 

Here's my code...

 

// 3. Use the mysql_query function to extract everything from the question table

 

$query = mysql_query("SELECT question, answer_a, answer_b, answer_c, answer_d, answer_e FROM t_questions");

while($row = mysql_fetch_assoc($query)){

echo $row['question']."<br />".$row['answer_a']."<br />".$row['answer_b']."<br />".$row['answer_c']."<br />".$row['answer_d'];

}

 

 

?>

 

 

Thanks for your insight

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.