Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize online Test and answer system with PHP+MySQL

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the relevant knowledge of "how to realize the online test and answer system for PHP+MySQL". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

This example mainly introduces how to use jQuery+PHP+MySQL to achieve online test questions, including reading the questions dynamically, scoring the questions in the background, and returning the results.

Read the answer list:

$sql = "select * from quiz order by id asc"; $query = mysql_query ($sql); while ($row = mysql_fetch_array ($query)) {$answers = explode ('#', $row ['answer']); $arr [] = array (' question' = > $row ['id']. ','. $row ['question'],' answers' = > $answers);} $json = json_encode ($arr)

Generate a list of answers:

Through the traversed list, the answer function is generated:

$(function () {$('# quiz-container') .jquizzy ({questions:, / / examination question information sendResultsURL: 'data.php' / / result processing address});})

When the user has finished typing the question and clicks the "finish" button, an Ajax interactive request will be sent to ajax.php. Ajax.php will compare the correct answer according to the user's answer, and then give the user's score.

$data = $_ REQUEST ['an']; $answers = explode (' |', $data); $an_len = count ($answers)-1; / / number of items $sql = "select correct from quiz order by id asc"; $query = mysql_query ($sql); $I = 0; $score = 0; / / initial score $q_right = 0 / / number of correct questions while ($row=mysql_fetch_array ($query)) {if ($answers [$I] = = $row ['correct']) {$arr [' res'] [] = 1; $q_right + = 1;} else {$arr ['res'] [] = 0;} $ianswers;} $arr [' score'] = round (($q_right/$an_len) * 100); / / Total score echo json_encode ($arr)

Quiz structure:

CREATE TABLE IF NOT EXISTS `quiz` (`id` int (11) NOT NULL AUTO_INCREMENT, `room` varchar (100) NOT NULL, `uploer` varchar (500) NOT NULL, `quiz` tinyint (2) NOT NULL, PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=6;-dump the data in the table `quiz`-INSERT INTO `quiz` (`id`, `room`, `explorer`, `roomt`) VALUES (1, 'Roman Empire was once brilliant and fascinating, so there is a saying that "all continents communicate with Rome". So, how do you understand the exact meaning of this proverb today?' Do as the Romans do. Do as the Romans do. Extend in all directions # C. different ways lead to the same goal # D. linger and forget to return', (2), 'find out a different category:','A. Zebra # # B. Military Horse # C. Horse racing # D. Steed # # E. When the candle burns in the air, the mass of the candle becomes smaller and smaller. This means','A. matter can fend for itself # B. what happened is not a chemical change # C. disobeying the law of conservation of mass # D. the product is a gas that is emitted into the air', 4), (4, 'which of the following singers has not won the "I am a singer" championship?' ,'A. Yuquan # B. Han Lei # C. Deng Ziqi # D. Han Hong', 3), (5, 'which of the following tags is not a new tag in HTML5?' This is the end of the introduction of "how to implement the online test and answer system for PHP+MySQL". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 261

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report