当前位置:Gxlcms > PHP教程 > 昨晚忙到凌晨3点都没解决的问题,大侠,今天晚能不熬夜不?HELP!

昨晚忙到凌晨3点都没解决的问题,大侠,今天晚能不熬夜不?HELP!

时间:2021-07-01 10:21:17 帮助过:16人阅读

想做一个在线答题系统,看看网上有个现成的,拿来试试,下载源码上传到sina云,为什么和原创的不一样呢?(答完题后没分数)
我的sina云地址:http://1.xyqcsmwly.sinaapp.com/quizphp/quiz.php

原创的演示地址:http://www.helloweba.com/demo/quiz/quiz.php

我的代码:
quiz.php
 $row['id'].'、'.$row['question'],		'answers' => $answers	);}$json = json_encode($arr);?>演示:如何使用jQuery+PHP+MySQL来实现一个在线测试项目	   

helloweba

如何使用jQuery+PHP+MySQL来实现一个在线测试项目


Powered by helloweba.com 允许转载、修改和使用本站的DEMO,但请注明出处:www.helloweba.com



connect.php


data.php


回复讨论(解决方案)

data.php


quizs.js
(function($) {    $.fn.jquizzy = function(settings) {        var defaults = {            questions: null,            startImg: 'images/start.gif',            endText: '已结束!',            shortURL: null,            sendResultsURL: null,            resultComments: {                perfect: '你是爱因斯坦么?',                excellent: '非常优秀!',                good: '很好,发挥不错!',                average: '一般般了。',                bad: '太可怜了!',                poor: '好可怕啊!',                worst: '悲痛欲绝!'            }        };        var config = $.extend(defaults, settings);        if (config.questions === null) {            $(this).html('

Failed to parse questions.

'); return; } var superContainer = $(this), answers = [], introFob = ' 请认真完成测试题。准备好了吗?

', exitFob = '' + config.endText + '请选择一个选项!', contentFob = '', questionsIteratorIndex, answersIteratorIndex; superContainer.addClass('main-quiz-holder'); for (questionsIteratorIndex = 0; questionsIteratorIndex < config.questions.length; questionsIteratorIndex++) { contentFob += '' + (questionsIteratorIndex + 1) + '/' + config.questions.length + '' + config.questions[questionsIteratorIndex].question + '
    '; for (answersIteratorIndex = 0; answersIteratorIndex < config.questions[questionsIteratorIndex].answers.length; answersIteratorIndex++) { contentFob += '
  • ' + config.questions[questionsIteratorIndex].answers[answersIteratorIndex] + '
  • '; } contentFob += '
'; if (questionsIteratorIndex !== 0) { contentFob += '< 上一题'; } if (questionsIteratorIndex < config.questions.length - 1) { contentFob += '下一题 >'; } else { contentFob += '完成'; } contentFob += ''; answers.push(config.questions[questionsIteratorIndex].correctAnswer); } superContainer.html(introFob + contentFob + exitFob); var progress = superContainer.find('.progress'), progressKeeper = superContainer.find('.progress-keeper'), notice = superContainer.find('.notice'), progressWidth = progressKeeper.width(), userAnswers = [], questionLength = config.questions.length, slidesList = superContainer.find('.slide-container'); function checkAnswers() { var resultArr = [], flag = false; for (i = 0; i < answers.length; i++) { if (answers[i] == userAnswers[i]) { flag = true; } else { flag = false; } resultArr.push(flag); } return resultArr; } function roundReloaded(num, dec) { var result = Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec); return result; } function judgeSkills(score) { var returnString; if (score === 100) return config.resultComments.perfect; else if (score > 90) return config.resultComments.excellent; else if (score > 70) return config.resultComments.good; else if (score > 50) return config.resultComments.average; else if (score > 35) return config.resultComments.bad; else if (score > 20) return config.resultComments.poor; else return config.resultComments.worst; } progressKeeper.hide(); notice.hide(); slidesList.hide().first().fadeIn(500); superContainer.find('li').click(function() { var thisLi = $(this); if (thisLi.hasClass('selected')) { thisLi.removeClass('selected'); } else { thisLi.parents('.answers').children('li').removeClass('selected'); thisLi.addClass('selected'); } }); superContainer.find('.nav-start').click(function() { $(this).parents('.slide-container').fadeOut(500, function() { $(this).next().fadeIn(500); progressKeeper.fadeIn(500); }); return false; }); superContainer.find('.next').click(function() { if ($(this).parents('.slide-container').find('li.selected').length === 0) { notice.fadeIn(300); return false; } notice.hide(); $(this).parents('.slide-container').fadeOut(500, function() { $(this).next().fadeIn(500); }); progress.animate({ width: progress.width() + Math.round(progressWidth / questionLength) }, 500); return false; }); superContainer.find('.prev').click(function() { notice.hide(); $(this).parents('.slide-container').fadeOut(500, function() { $(this).prev().fadeIn(500); }); progress.animate({ width: progress.width() - Math.round(progressWidth / questionLength) }, 500); return false; }); superContainer.find('.final').click(function() { if ($(this).parents('.slide-container').find('li.selected').length === 0) { notice.fadeIn(300); return false; } superContainer.find('li.selected').each(function(index) { userAnswers.push($(this).parents('.answers').children('li').index($(this).parents('.answers').find('li.selected')) + 1); }); progressKeeper.hide(); var resultSet = ''; if (config.sendResultsURL !== null) { var collate = []; var myanswers = ''; for (r = 0; r < userAnswers.length; r++) { collate.push('{"questionNumber":"' + parseInt(r + 1, 10) + '", "userAnswer":"' + userAnswers[r] + '"}'); myanswers = myanswers + userAnswers[r]+'|'; } $.getJSON(config.sendResultsURL,{an:myanswers},function(json){ if(json==null){ alert('通讯失败!'); }else{ var corects = json['res']; $.each(corects,function(index,array){ resultSet += '' + (corects[index] === 1 ? "#"+(index + 1)+"": "#"+(index + 1)+"")+''; }); resultSet = '

' + judgeSkills(json.score) + '
您的分数: ' + json.score + '

' + resultSet + ''; superContainer.find('.result-keeper').html(resultSet).show(500); } }); } //superContainer.find('.resultsview-qhover').hide(); $(this).parents('.slide-container').fadeOut(500, function() { $(this).next().fadeIn(500); }); return false; }); };})(jQuery);

文件目录:

原创在线答题源码地址:http://www.helloweba.com/downsoft/297/

大侠们,帮忙看看,谢谢!

quiz.sql

-- phpMyAdmin SQL Dump-- version 3.2.0.1-- http://www.phpmyadmin.net---- 主机: localhost-- 生成日期: 2015 年 04 月 04 日 13:49-- 服务器版本: 5.5.8-- PHP 版本: 5.3.3SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;/*!40101 SET NAMES utf8 */;---- 数据库: `lrfbeyond_demo`---- ------------------------------------------------------------ 表的结构 `quiz`--CREATE TABLE IF NOT EXISTS `quiz` (  `id` int(11) NOT NULL AUTO_INCREMENT,  `question` varchar(100) NOT NULL,  `answer` varchar(500) NOT NULL,  `correct` tinyint(2) NOT NULL,  PRIMARY KEY (`id`)) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=6 ;---- 转存表中的数据 `quiz`--INSERT INTO `quiz` (`id`, `question`, `answer`, `correct`) VALUES(1, '罗马帝国曾一度辉煌,令人神往,故有“条条大陆通罗马”一说。那么,今天你是怎样理解这一谚语的准确含义的?', 'A.入乡随俗 ###B.四通八达 ###C.殊途同归 ###D.流连忘返', 3),(2, '找出不同类的一项:', 'A.斑马 ###B.军马 ###C.赛马 ###D.骏马 ###E.驸马', 5),(3, ' 蜡烛在空气中燃烧,蜡烛质量逐渐变小。这说明', 'A.物质可以自生自灭###B.发生的不是化学变化###C.不遵守质量守恒定律###D.生成物为气体,散发到空气中了', 4),(4, '以下哪位歌手没有获得过《我是歌手》总冠军?', 'A.羽泉###B.韩磊###C.邓紫棋###D.韩红', 3),(5, '下列哪个标签不是HTML5中的新标签?', 'A.<article>###B.<canvas>###C.<section>###D.<sub>', 4);

感谢版主大人xuzuning的回复,补齐4个文件,仍不能统计出结果。
补齐4个文件后的测试连接:http://2.xyqcsmwly.sinaapp.com/quiz.php

Warning: Cannot modify header information - headers already sent by (output started at /data1/www/htdocs/795/xyqcsmwly/2/quiz.php:1) in connect.php on line 12


你自己 F12

感谢,xuzuning,程序已正常运行。估计和SINA云身份认证有关,谢谢!

人气教程排行