Jump to content

Hlp Pls..


googlemaniac

Recommended Posts

hi..i have a quiz site wherein there are 35 levels.There is a leader board which shows the points of all players.when he crosses level 1 the leader board should update his score..like add one to his score and put him on top of the table [if he is the top scorer]..how is this possible?The question is put up in 1.php the answer to be compared is in 2.php and the next level is 3.phpwhat is the sql query to create a field for this?how will 2.php handle this to update the leaderboard?thanku in advance..

Link to comment
Share on other sites

It's probably going to be a lot easier if you have one page display all of the questions and record the answers instead of duplicating your code on every page. Are these questions coming out of a database or somewhere else, or did you just write them directly on the page?

Link to comment
Share on other sites

It will be best to store the questions and choices in an array, and do this all on one page. You can create an array of questions like this:

$questions = array(  array(	'question_text' => 'True or false?',	'correct_choice' => 0,	'choices' => array( 	  'True',	  'False',	  'A bag of walnuts'	)  ),  array(	'question_text' => 'Which of these is prime?',	'correct_choice' => 2,	'choices' => array( 	  '1581',	  '27644433',	  '35742549198872617291353508656626642567',	  'A bag of walnuts'	)  ),  array(	'question_text' => 'What is the capital of Assyria?',	'correct_choice' => 3,	'choices' => array( 	  'Ur',	  'Susa',	  'Kish',	  'Assur'	)  ));

So that's an array of 3 questions, where each question has the question text, the correct choice, and all of the choices. Arrays start the index numbering at 0, not 1, so the first element in the question array is $questions[0], not $questions[1]. So on the first question where it says the correct choice is 0, that means it's the first item in the choices array for that question. If you define all of your questions like that, then you can use a counter to keep track of which question they're on and each time they submit a question you check the answer against the array, update the database and score table, and output the next question. That way at least you can keep all of your code in one place.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...