/    Sign up×
Community /Pin to ProfileBookmark

How to saved jquizme test result on database?

Anybody here familiar with jquizme? I have take a look at the codes of jquizme(jQuizMe-uncompressed.js), but I can’t figure out how can I pass the test result on the database.

[URL=”http://code.google.com/p/jquizme/”]http://code.google.com/p/jquizme/[/URL]

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@eval_BadCode_Feb 06.2012 — This is really a javascript question, but since it's going to involve javascript, php, and mysql it's OK to post it here. I just think you'll get better help in the javascript subforum is all.

To answer your question:

That depends a lot on how you want to store the result. :eek: you need to be much more specific. Do you want each question stored, or only a summary?

Moreover, the results could be very easily spoofed unless you are careful about how you implement this javascript. From the examples I looked at, none of them were very secure. But if it's just for fun, who cares.

To be a bit more secure:

Basically the answers would need to be stored serverside, then you serve up the question, have them answer it, send that answer to the server to compare to the correct answer (PERFECT TIME TO STORE THE ANSWER RIGHT HERE), and then return the result back to the browser.

Edit:

I guess the answer is either: more javascript (plus a <form> with hidden fields), or ajax, or a old fashion 1 question per page form-type website. There's actually a ton of ways you can do what you want. I made a post about this recently: http://www.webdeveloper.com/forum/showthread.php?t=256345 which has a working example AND I'm sure it has everything you need to know to do what you want. You could also do this, which is a complete shot in the dark... serialize the quiz object or turn it into a string with json (if it contains a ton of questions). Then you can access the object in PHP after decoding the json string.
Copy linkTweet thisAlerts:
@anishgiriauthorFeb 06.2012 — Thanks for the answer, I only want to store the summary of the score. For exampe in the [CODE]simple-html-quiz.html[/CODE] from demo files in jquizme. I will to save the result in which after you completed the exam, your result will be be saved on the database.

I am trying to find what codes(variable) in[CODE] jQuizMe-uncompressed.js[/CODE] the final result is stored so I can past the value in which ever possible way a client side variable can pass value on the server side.
Copy linkTweet thisAlerts:
@anishgiriauthorFeb 07.2012 — Thanks man, though I am not that yet familiar with jquery, I have use some open source jquery together with php, but with this jquiz, I seems can't figure out how to get the total test value.

[B]Options.statusUpdate

quizInfo.score is the current score.

quizInfo.total is the number of questions that are in the quiz.

[/B]



[CODE]options.statusUpdate = function( info, $quiz ){
$( "#score-right" ).html( info.right.length );
$( "#score-wrong" ).html( info.wrong.length );

if( info.hasQuit ){
var response = ( info.score >= 50 ) ? "Good job!" : "You need help." ;
$( $quiz ).find( ".q-statDetails" ).hide();
$( $quiz ).find( ".q-extraStat" ).html( response );
}
};[/CODE]


For example in the code above how can I assign the result to the javascript var x? Or how can I assign the value of [B]quizInfo.score[/B](from Options.statusUpdate) to var x?

[CODE]
<script language="JavaScript">
var x = 'anything goes'
location.href="myPage.php?a=" + x;
</script>[/CODE]
Copy linkTweet thisAlerts:
@eval_BadCode_Feb 07.2012 — I think I know something that you don't which is where you are having issues with solving this problem. This is OH SO terribly common when dealing with JQuery. There is also a good reason behind it. Lets look at the top of some of the example scripts that are provided with this javascript library:
[CODE]
$( function($){
.... all of the quiz stuff ....
}
[/CODE]


What is $?
[CODE]
function (E, F) {
return new o.fn.init(E, F);
}
[/CODE]


Ok... well what is function(E, F) ???? That is an anonymous self calling function. ?!?!?!?!?! WAT?

Is jquery some type of function programming experiment gone terribly wrong? No: (maybe...) there are good reasons to do this. it does not pollute the global variable environment with a bunch of variables which would conflict and cause mayhem should you ever want to have two or three javascript libraries on the same page! What this means for you is that you can [COLOR="Sienna"]not[/COLOR] do this:

[CODE]
$( function($){
.... all of the quiz stuff ....
}

alert(quiz.info);
[/CODE]

because quiz.info is not accessible at this level of [B][U]scope[/U][/B]. It may not even exist as a reference anywhere at all. The correct way to do this according to the documentation and your needs would be like this: (highlighted in red):

[CODE]
$( function($){
var undefVar, answerInfo = ["When == is called, type casting is performed. ", "=== does no type casting."],
arr = [1, 2, 3, 4];
arr["five"] = 5;

options = {
help: "Try...<ul><li><a href='https://developer.mozilla.org/en/a_re-introduction_to_javascript' target ='_blank'>A Re-introduction to Javascript</a><li><a href='http://www.hunlock.com/blogs/Mastering_Javascript_Arrays' target='_blank'>Mastering Arrays</a></li><li><a href='http://www.jibbering.com/faq/faq_notes/type_convert.html' target='_blank'>Type casting</a></li></ul>",
intro: "Find out if you know the basics in <i>Javascript</i>.<br/>Follow the link back to make your own quiz.",
allRandom: true,
title: "Basic Javascript Quiz1",
[COLOR="DarkRed"] statusUpdate: function( info, $quiz ){
alert(info);
alert($quiz);
} [/COLOR]

};

$("#quizArea").jQuizMe(quiz, options);
});
[/CODE]


Which is actually a procedural way [U]of writing this ENTIRE QUIZ as a self calling function[/U], like this:
[CODE]
$( function($){
$("#quizArea").jQuizMe(
{
multi: [
{
ques: "!!-1 = ?",
ans: ( !! -1),
ansSel: ["error", "false"],
ansInfo: "!!x is the same as Boolean(x).<br/>More info on <a href='http://www.jibbering.com/faq/faq_notes/type_convert.html' target='_blank'>Type conversion</a>"
}
],
multiList: [
{
ques: "Which is not a javascript keyword.",
ans: "local",
ansSel: ["new", "delete"]
},
{
ques: "What function is x?<br/><code>arr = [ 1,2,3,4 ];<br/>arr.x();<br/>alert(arr) //[2,3,4]</code>",
ans: "shift",
ansSel: ["pop", "push", "unpush"]
}
],
tf: [
{
ques: "(1 == '1') = ?",
ans: (1 == '1'),
ansInfo: answerInfo[0]
},
{
ques: "(1 === '1') = ?",
ans: (1 === '1'),
ansInfo: answerInfo[1]
},
{
ques: "(0.1 + 0.2)",
ans: (0.1 + 0.2),
ansSel: ["0.3"],
ansInfo: "(0.1 + 0.2) = " + (0.1 + 0.2)
},
{
ques: "(0.1 + 0.1) == 0.2",
ans: ((0.1 + 0.1) == 0.2),
ansInfo: "(0.1 + 0.1) = " + (0.1 + 0.1)
},
{
ques: "What value is returned?<br/><code> function(undefVar){<br/>return undefVar == null;<br/>};<br/></code>",
ans: (undefVar == null),
ansInfo: answerInfo[0] + "Both 'undefined' and 'null' return false when converted to a boolean."
},
{
ques: 'The following returns what value?<br/><code>isNaN( "1" );</code>',
ans: isNaN("1"),
ansInfo: 'Type conversion was performed.'
}
],
fill: [
{
ques: "What is the value of x?<br/><code>x = '1'+2+3</code>",
ans: ("1" + 2 + 3)
},
{
ques: "What is the value of x?<br/><code>x = 9 + 8 + '7'</code>",
ans: (9 + 8 + "7")
},
{
ques: "<code>arr = [ 1, 2, 3, 4 ]; <br/>arr[ 'five' ] = 5;</code><br/>arr.length == ?",
ans: arr.length
}
]
},
{
help: "Try...<ul><li><a href='https://developer.mozilla.org/en/a_re-introduction_to_javascript' target ='_blank'>A Re-introduction to Javascript</a><li><a href='http://www.hunlock.com/blogs/Mastering_Javascript_Arrays' target='_blank'>Mastering Arrays</a></li><li><a href='http://www.jibbering.com/faq/faq_notes/type_convert.html' target='_blank'>Type casting</a></li></ul>",
intro: "Find out if you know the basics in <i>Javascript</i>.<br/>Follow the link back to make your own quiz.",
allRandom: true,
title: "Basic Javascript Quiz1"
});
});
[/CODE]


[code=php]
<?php
$s = function($a = "If you are only familiar with one type of programming, procedural, n") {
foreach(explode("n",
wordwrap( $a .
preg_replace_callback('/ss+/', function ($m) { return ' '; }, <<<LS
then functional programming might seem a bit
intimidating at first.
Unfortunately
I can only show you the rules; to master
the rules and apply them in a meaningful way
is something you must do for yourself.
LS
))) as $line) echo trim($line),"n";
};

$s();
[/code]


If you pursue this long enough, I think you will find that the reason behind the "process" is to transform information, everything else is just building up to that.
×

Success!

Help @anishgiri spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...