cleecaldwell Posted July 31, 2011 Share Posted July 31, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/243370-form-with-information-from-database/ Share on other sites More sharing options...
voip03 Posted July 31, 2011 Share Posted July 31, 2011 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! } Quote Link to comment https://forums.phpfreaks.com/topic/243370-form-with-information-from-database/#findComment-1249760 Share on other sites More sharing options...
cleecaldwell Posted July 31, 2011 Author Share Posted July 31, 2011 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... Quote Link to comment https://forums.phpfreaks.com/topic/243370-form-with-information-from-database/#findComment-1249765 Share on other sites More sharing options...
trq Posted July 31, 2011 Share Posted July 31, 2011 You need to break your problem into smaller pieces and solve each of them one by one. Programming isn't just about learning a languages syntax. You need to think a problem through. Quote Link to comment https://forums.phpfreaks.com/topic/243370-form-with-information-from-database/#findComment-1249766 Share on other sites More sharing options...
voip03 Posted July 31, 2011 Share Posted July 31, 2011 SELECT id, Q, A, FROM q&a Where id=$randomstring; http://www.hscripts.com/tutorials/mysql/select-column.php Quote Link to comment https://forums.phpfreaks.com/topic/243370-form-with-information-from-database/#findComment-1249915 Share on other sites More sharing options...
voip03 Posted July 31, 2011 Share Posted July 31, 2011 Google it ->mysql select only multiple fields You can learn a lot . Quote Link to comment https://forums.phpfreaks.com/topic/243370-form-with-information-from-database/#findComment-1249916 Share on other sites More sharing options...
cleecaldwell Posted August 4, 2011 Author Share Posted August 4, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/243370-form-with-information-from-database/#findComment-1251547 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.