googlemaniac Posted November 16, 2009 Share Posted November 16, 2009 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 More sharing options...
kirbyweb Posted November 17, 2009 Share Posted November 17, 2009 Why don't you just have it update at the last question? Link to comment Share on other sites More sharing options...
googlemaniac Posted November 18, 2009 Author Share Posted November 18, 2009 each level is tuf..and i want to get the ###### outta everyone els wen sum1 crosses a particular level.. Link to comment Share on other sites More sharing options...
justsomeguy Posted November 18, 2009 Share Posted November 18, 2009 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 More sharing options...
googlemaniac Posted November 19, 2009 Author Share Posted November 19, 2009 directly onto the page.. Link to comment Share on other sites More sharing options...
justsomeguy Posted November 19, 2009 Share Posted November 19, 2009 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.