How to Create Quiz using PHP, MySQL and Jquery - php

I need to create a quiz/multiple choice questions with correct answer.
Its basically for vocabulary, so 'A definition will be shown' and then possible Words would be provided.
My previous plan: Select word and meaning from Database, then generate the form for answers and then when user answers move on to next word.
I would be selecting words from database randomly, to keep it different each time. Also, I would be noting down how many times the word was answered correctly or incorrectly. So, that later on I can arrange them according to difficulty also.
My Problem: How do I update to the next question when user answers the question? How do I move on to the next problem, I thought I could do it easily using Jquery but integrating Jquery with PHP is tougher than it seems. I searched for plugins but they basically hard code the question in the JS, I wish to take them out from Database which would be updated as required.
Its a pet project, just so that I can help people practice their Vocabulary. I have implemented the basic design and also developed space for people to Contribute their words. The plans for expansion are vast with many possible directions, later, ranking system, facebook integration, etc. etc. I wish to finish it by the end of this weekend, so that I can move on to other things.
You can see vocabulary.dharamveer.in but you would only get idea about the basic application, not much regarding the problem at hand.
Eagerly awaiting your answers, thank you for help in advance :)

ajax is definitely the way to go with this, use ajax with json to load up your questions and then just have jquery loop through them.
Option 1
If you are creating a set length quiz, you could always create the full quiz off the start. That way you can ensure there are no repeating questions without the need to save anything. Then you can just loop through the whole quiz without making a call for each question.
Option 2
If it's a never ending quiz, then maybe you can do the questions in batches. Then when the user is done the old batch you can send that one back as a parameter and exclude them from the new batch. If your batches are large (for example 50 questions), than it would be at the very least 50 questions until a repeat and that's the worst case. Depending on how many questions you have total, you could end up with multiple batches before a repeat.

I would use Ajax to he the next question. Have another page simply retrieve a single random question and retrieve it with jquery Ajax.

Related

How do you get the Respondent ID from a Survey Monkey survey?

The Story
I'm in the beginning stages of creating a video teaching engine for a retailer incentive program my company is putting together. The way it will work is that retailers will register and be provided the ability to login to the system to access the content. Once logged in, retailers will watch short videos about my company's products and then they will be asked to answer a 3 or 4 question quiz about the product. The idea is that based on their responses they will earn the incentive. For example: the user passes 10 quizzes then they get a significant discount on their next order from my company.
The Problem
So I'm getting to the point where I'm researching different ways to go about putting together the whole program and am trying to determine the best way to write it. One thought so far is to create the quizzes as SurveyMonkey surveys and then process the results from that to award the incentive. I've been looking through the SurveyMonkey PHP API and I see that there is a method to get_responses(), which seems like it's exactly what I'm after. The problem is, is that this method takes a respondent_id for one of the parameters, which I have no idea how you get.
The Question
How do I get the respondent_id after the user has taken the quiz/survey? Ideally I would like to get this, then get the response information, process it, and then output a result/increment the number of incentives earned. I did do some looking around here on StackOverflow and found this: Get details about survey monkey's questions and answers by id, but it doesn't really look like what I'm after.
If this isn't something that SurveyMonkey can really do, that's OK, as I'm more just looking for an efficient way of doing it, short of having to build the whole thing myself. As always any help or info is appreciated!
In order to get the responses, you need a list of respondent_ids. And in order to get the respondent_ids, you need to have the survey_id(s) from the get_survey_list API call. Note that the responses only includes a question_id that maps to the question (text and possible answers) in the output of get_survey_details (with the exception of open-ended text answers).
If this isn't something that SurveyMonkey can really do, that's OK, as I'm more just looking for an efficient way of doing it, short of having to build the whole thing myself.
It takes a modest code infrastructure to get all these pieces put together. You may want to start with the API Console and see if the output of the API can be of use to you.
https://developer.surveymonkey.com/mashery/get_respondent_list seems to be what you are looking for, from there you can get the response information.

current status of mysql table displayed every x seconds

Ok. I didn't know how to put this question in Title so here is a quick description.
Let's say I have site with some promotional stuff to give for free (or not:).
When I have something to give I announce this on facebook and twitter etc. and people can come to website and fill quick form, couple quick questions and of course name and address.
But the problem is I have for example 20 pieces of this thing to give for free.
When you submit the form this goes automatically to database table.
I know how to display current status for this offer with some PHP (like: there's only 12 items left.hurry up!), there is also no problem with refreshing this every couple seconds with AJAX. But problem I see in here is when let's say this will become more popular and I will have many offers during short time.
I don't want database to be overloaded with queries from hundreds of people every two seconds.
Is there any way to send just one query every two seconds (somewhere on the sever?) and just somehow update value from this query in any browser currently visiting the website?
I'm not sure if this is clear question but what I'm asking is what would be the best practice for this kind of situation.
Is my concern about overloading the database even reasonable?
And extra problem...
In this particular situation - with the limit for amount of people that can participate - is there any threat that I can have strange behavior when two people will send form in exactly the same time when there is only one item left?
I would love to see any directions in this subject. Even general one will do :)
PS: No, english is not my first language :)
Thx
Can't you have one script loading from the database and save it somewhere that isn't the database (a file, preferably) and then it can be extracted from there? This will include a cronjob for that script to be run every 5 second.

A better alternative to my approach (Symfony 1.4 modules)

In my quest for perfection and minimalism, I post this question here to you guys, seeking if there is a better and more alternative option than the one I have.
I have a module with two different templates. Essentially the first is a quiz template, the second is a page that displays the results of the quiz. The quiz is a form whereas the results page is not. On my quiz page, the action for the form is essentially 'module/quizResults?id='.$quizId
Now for the quiz action, I do a db query to retrieve the set of questions that belong to the quiz and then when the post takes place the action that is being called is that of quizResults, out here I must compare the answer options of my user against the correct answer options for the questions of a quiz. Essentially, I have to again query the db to retrieve the set of questions for the quizzes in another db. I feel this is a slight overkill and I am irked.
I think there can be better solutions. I can post back to the same quiz page, but then that demands more complexity on the template as well as the action making things a little murkier.
Any alternatives?
Thanks
There are a few options you could implement to do what your asking, but you need to ask yourself will the added complexity outweigh the minor performance gains, especially if the queries are optimized.
Option #1: Session
When you load the questions from the quiz action, you could add the questions to the user's session, then when the user posts the quiz for the results, simply refer to the questions stored in session.
Option #2: Memcached
Same as above, but instead of storing the questions to the user session, you could store the questions into memcache, so when you calculate the results, instead of making another database query, you pull the questions from the cache layer instead.
You're trying to solve this the wrong way.
Performance is absolute no issue here. But what is an issue is programmer performance. If you have to manually craft each query and pass all the right variables along it's going to take a lot of your time. What you need is a framework that will allow you to build the necessary logic in a quicker way. If you know how to do this perfectly you will make a lot of money, until then you'll have to scratch along just like the rest of us :P
Assuming the submission page should display all-good if all correct, or the incorrect ones if not, I would write a myprojectQuestionValidator and use that in my question form, one for each question/answer. The validator can then check each answer against the correct one in the database. Agreed with Frits, don't worry about performance - that's premature optimization IMO. Break the app into conceptual components, and worry about optimization when you need to.

Need to add "This answer helped" for an FAQ/KB using PHP/MySQL

I've found ways to rank existing values but it's been awhile and I'm not sure the best way to add a "This answered my question" function to my KB/FAQ. I guess my biggest problem is separating multiple queries into individual ones so I can plug this feature in. I'm assuming I'd just have to add a insert into the database that will +1 each time someone clicks the button, but it's been awhile and I haven't done this before.
As a further clarification, Im using this within a Facebook app I'm making so need to rate individual answers that are generated by the search of my knowledge base to produce better answers. It's all dynamic, so no static pages.
Haven't found an answer that could help thus far.
Consider adding something like the Google Plus One button to your site. It's very easy to implement and you don't have to worry about any backend stuff as a result.
Or search on google.

data system design

Need some ideas/help on best way to approach a new data system design. Basically, the way this will work is there will be a bunch of different database/tables that will need to be updated on a regular (daily/weekly/monthly) basis with new records.
The people that will be imputing the data will be proficient in excel. The input process will be done via a simple upload form. Then the system needs to add what was imported to the existing data in the databases. There needs to be a "rollback" process that'll reset the database to any day within the last week.
There will be approximatively 30 to 50 different data sources. the main primary interface will be an online search area area. so all of the records need to be indexed/searchable.
Ideas/thoughts on how to best approach this? It needs to be built mostly out of php/mysql.
imputing the data
Typo?
What you are asking takes people with several years formal training to do. Conventionally, the approach would be to draw up a set of requirements, then a set of formal specifications, then the architecture of the system would be designed, then the data design, then the code implementation. There are other approaches which tend to shortcut this. However even in the case of a single table (although it does not necessarily follow that one "simple upload form" corresponds to one table), with a single developer there's a couple of days work before any part of the design could be finalised, the majority of which is finding out what the system is supposed to do. But you've given no indication of the usage nor data complexity of the system.
Also what do you mean by upload? That implies they'll be manipulating the data elsewhere and uploading files rather than inputting values directly.
You can't adequately describe the functionality of a complete system in a 9 line SO post.
You're unlikely to find people here to do your work for free.
You're not going to get the information you're asking for in a S.O. answer.
You seem to be struggling to use the right language to describe the facts you know.
Your question is very vague.

Categories