dyous87 Posted April 22, 2007 Share Posted April 22, 2007 Ok everyone I'm pretty much new to php programming but my university has asked me to create and online test type thing for incomming freshmen to take next year. I have two sides to this project, an admin side and a student side. The admin side allows you to add chapters, questions and answers to a mysql database. That is all complete. Now i need to work on the student side which will display the questions from mysql database. I have been trying to figure out how to do this and I have searched around the web but I have been unable to. Is there anyone here he would be kind enough to explain this to me or maybe walk me through it. I would really appreciate it. Thank you in my mysql database I have the quiz question, answers and number of chances allowed. I also have set what page it should go to if the question is wrong or right. I need to know how to get this information to appear in a website using php. It's supposed to be dynamic so that the quiz is working right off the database and i don't need to write and html or php page for every question. I read something about outer join in order to get this done but I'm not exactly sure what that is. bare with me i definitely butchered this code, i have been reading through tutorials and i am trying to get the hang of this. anyway here is what i have: <?php $link = mysql_connect('localhost', 'root', 'pw'); mysql_select_db('fordham', $link); $result = mysql_query('SELECT * FROM pages WHERE page_number = 1' . $page_number, $link); ?> mysql_query('SELECT * FROM pages WHERE page_number=1', $link); if $page_type_id=1 { mysql_query('SELECT * FROM pages_data', $link); echo $row pages_data; } if $page_type_id=2 { mysql_query('SELECT * FROM questions', $link); <form method="post" action="begin.php?id=<?php echo $page_type_id ?>"> <p>Question: <?php echo $question ?></p> <select name="answer"> <?php while ($answer = mysql_fetch_array($answers)) { ?> <option value="<?php echo $answer['id'] ?>"><?php echo $answer['answer'] ?></option> <?php } ?> <?php </select> <p><input type="submit" value="Submit" /></p> </form> I know it isn't complete yet and when i run it on my server nothing happens so there's stuff wrong it it. basically what i want to happen is i want to select from my pages table where the page_number=1. that's to begin. then if page_type_id = 1 i want it to select from pages_data. if page_type_id=2 i want it to select from questions. then i want it to print the question for the page and i want it to list the answers from question_response table in radio boxes. i want it to then check against the database for the correct answer. 1=wrong 2=right. if it's right i want it to go to the next question if it's wrong i want them to have another chance. three chances in all. i'm not sure if this is all supposed to be simpler then i'm making it out to be but i'm very new with php and just trying to figure this stuff out. i really appreciate all your help. Link to comment https://forums.phpfreaks.com/topic/48086-php-online-test-help/ Share on other sites More sharing options...
hackerkts Posted April 22, 2007 Share Posted April 22, 2007 Take a look at this, hope this helps. http://www.php-mysql-tutorial.com/php-mysql-select.php Link to comment https://forums.phpfreaks.com/topic/48086-php-online-test-help/#findComment-235007 Share on other sites More sharing options...
dyous87 Posted April 22, 2007 Author Share Posted April 22, 2007 i actually tried that tutorial, it wasn't much help but thanks for your help anyway. i appreciate it. Link to comment https://forums.phpfreaks.com/topic/48086-php-online-test-help/#findComment-235014 Share on other sites More sharing options...
hackerkts Posted April 22, 2007 Share Posted April 22, 2007 Maybe you can elaborate further more about your questions and we could help out. Link to comment https://forums.phpfreaks.com/topic/48086-php-online-test-help/#findComment-235017 Share on other sites More sharing options...
dyous87 Posted April 22, 2007 Author Share Posted April 22, 2007 Ok I'll explain what I am trying to do. Basically I have a mysql database that i'm making my php scripts connect to. In my data base I have different tables called: pages pages_data question_data question_types questions questions_response I'm trying to code in php a online test that will pull a page out of the page table. each page has an id, either 1 or 2. if it's 1 it needs to load a content page from pages_data, if its 2 it needs to load a question from questions. when a content page is loaded i need to have a button that will automatically redirect the user to the next page number from the data base. if it loads a question page it must also provide radio buttons for the answers which are from question_data. one answer is the right one. if the right one is selected it should imput that the user answered that question correctly under question_response. the user has 3 tries to get it right. if on the third try it's still wrong it will redirect the user to the next page and input that that user got the question wrong in question_response. I've been trying to desperately figure this out for two days now. Here is my current code: <?php session_start(); $link = mysql_connect('localhost', 'root', 'usa4552'); mysql_select_db('fordham', $link); $question = mysql_query('SELECT * FROM questions, question', $link); $answer = mysql_query('SELECT * FROM question_data, question_data_answer', $link); $page_type_id = mysql_query('SELECT * FROM pages, page_type_id', $link); $result = mysql_query('SELECT * FROM pages WHERE page_number = 1', $link); if ($page_type_id == 1) { $result = mysql_query('SELECT * FROM pages_data WHERE page_id = page_id FROM pages', $link); while ($row = mysql_fetch_array($result)); echo $row['pages_data']; } else { if ($page_type_id == 2) { $result = mysql_query('SELECT * FROM questions WHERE page_id = page_id FROM pages and SELECT * FROM question_data WHERE question_id = question_id FROM questions', $link); while ($row = mysql_fetch_array($result)); ($_SERVER['REQUEST_METHOD'] == 'POST'); $question = $_POST['question']; $answer = $_POST['answer']; $result = mysql_query('SELECT * FROM question_data WHERE question_data_correct = 2', $link); } if ($answer == $result) { $_SESSION['chances'] = 1; mysql_query("INSERT into questions_response (question_id, question_response_answer, user_id')"); } else { if ($_SESSION['chances'] == 3) { mysql_query("INSERT into questions_response (question_id, question_response_answer, user_id')"); } else { $_SESSION['chances'] += 1; } } } ?> <html> <head> <title>Student Test</title> </head> <body> <h1>Integrity Test</h1> <form method="POST" action="begin.php"> <p><?php echo $question ?></p> <p> <?php while ($row = mysql_fetch_array($result)) { ?> <label><input type="radio" name="answer" value="<?php echo $answer['answer'] ?>" /> <?php echo $answer['answer'] ?></label><br /> <?php } ?> <input type="hidden" name="question" value="<?php echo $question_id; ?>" /> </p> <p><input type="submit" value="Submit" /></p> </form> </body> </html> the only thing that it loads on the page is a radio button and an input button. I would really appreciate any help! thanks Link to comment https://forums.phpfreaks.com/topic/48086-php-online-test-help/#findComment-235604 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.