Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.