A php Online QUIZ

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
skp
Forum Newbie
Posts: 9
Joined: Fri Jul 10, 2009 7:58 am

A php Online QUIZ

Post by skp »

I am developing an online php quiz in which wach user has to be given random set of questions. I just wanted to know is there any way to get (all)the questions from the database in one fetch or we have to retrieve each question every time for all concurrent users .I think this may increase the load on the database...?
Thanks in advance
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: A php Online QUIZ

Post by jackpf »

What questions from the database?

How are you hoping to retrieve them?
User avatar
genconv
Forum Commoner
Posts: 34
Joined: Sun Jul 05, 2009 9:27 am

Re: A php Online QUIZ

Post by genconv »

You can fetch all questions for one user and store them in the session.
skp
Forum Newbie
Posts: 9
Joined: Fri Jul 10, 2009 7:58 am

Re: A php Online QUIZ

Post by skp »

jackpf wrote:What questions from the database?

How are you hoping to retrieve them?
Questions means, the ( s.no, question, ans1, ans2,ans3,ans4, right answer) . All these are to be retrieved from the db, so that database is touched only once. But here i need to show only one question at a time. So , till that i hv to store the other questions somewhere. This may be in sessions.Other ways to do so also welcome. I just wanted to reduce the load on the db ( avoiding fetching questns each time from the db).
skp
Forum Newbie
Posts: 9
Joined: Fri Jul 10, 2009 7:58 am

Re: A php Online QUIZ

Post by skp »

genconv wrote:You can fetch all questions for one user and store them in the session.
Thanks for ur reply.
Btw can u suggest any other way to do this other than using sessions (bcoz its difficult to store the entire resultset data into sessions & retrieving them back) ...?
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: A php Online QUIZ

Post by jackpf »

Well, you just have the query

Code: Select all

SELECT * FROM `Questions`
and then put it in a while() loop. What's the problem with that? Why do you have to put it in a session? Sounds completely pointless to me.
skp
Forum Newbie
Posts: 9
Joined: Fri Jul 10, 2009 7:58 am

Re: A php Online QUIZ

Post by skp »

jackpf wrote:Well, you just have the query

Code: Select all

SELECT * FROM `Questions`
and then put it in a while() loop. What's the problem with that? Why do you have to put it in a session? Sounds completely pointless to me.
Well, this is an online quiz in which each user will be given diff set of questions. So in this i dont want to flood the DB for fetching questions each time. So we can fetch once from db using select * from query. But have to be stored some where , bcoz only one question is to be shown to the user at a time. when he clicks 'next' button, the next questions shud be displayed. So suggest me now..
thanks
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: A php Online QUIZ

Post by jackpf »

As I said in one of your other threads, sessions basically are databases. You still have to retrieve the data.
skp
Forum Newbie
Posts: 9
Joined: Fri Jul 10, 2009 7:58 am

Re: A php Online QUIZ

Post by skp »

ok . so I guess u are trying to say retrieving from database each time for each question for each user will be the most suitable solution. So this may lead to server overload ( in the database engine) . So hw to avoid such a problem.....?
I am using WAMP( APache server ) .I Need to support minimum of 200 concurrent users.
Thanks in advance.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: A php Online QUIZ

Post by jackpf »

Just make sure you're data is normalised, optimised, and you're not doing any crazy joins or anything.

Just straight SELECT queries take about 0.0001 seconds or something, I doubt 200 users concurrently would do too much damage.

You could use AJAX, rather than requesting whole new pages, as I think this is faster and requires less bandwidth etc, since the connection is kept open. Idk, you could give it a try....
Post Reply