creating a input parser and countdown timer for trivia aplic

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
dvsmasta
Forum Newbie
Posts: 2
Joined: Thu Dec 12, 2002 6:43 pm

creating a input parser and countdown timer for trivia aplic

Post by dvsmasta »

I need to learn how to make an input parser for a trivia application i am making. I need to take the users input, and on the following page display if they answered correctly or not, and if not i will simply output the correct answer..

i am doing this in an interesting way.. i have a mySQL database set up with a table for the questions and answers...
anoter table is set up for the player information such as login name, pass, and stats..

all i really need to know how to do.. or need some help determining how to do, is parse the users input and compare it to the answer in my database.. ( in other words i want it to be a fill in the blank style trivia game.. )

ALSO.. i need help with how i can implement a timer for it... like a countdown from 15 or 30 sec. to 0.. then load next page if there is no answer given.. =)

thank for you help everyone =)
dvsmasta
Forum Newbie
Posts: 2
Joined: Thu Dec 12, 2002 6:43 pm

Post by dvsmasta »

any help would be appreciated
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

Well for the page timer you could just use this..

<META HTTP-EQUIV="REFRESH" CONTENT="replace_with_time_in_seconds_before_jump;URL=replace_with_next_page_to_go_to">

..just place it in the HEAD of your page..

..as for the database stuff..

Code: Select all

<?php

function checkanswer($question_id,$users_answer)
{

$result=mysql_num_rows(mysql_query("SELECT * FROM `your_table` WHERE `question_id`='$question_id' AND `answer`='$users_answer'");

if($result<=0)
{
return "no";
}
else
{
return "yes";
}

}


//to check the answer just do the following
//and make sure you have the two variables
//question_id and users_answer setup.
//
//if you get stuck just e-mail me


if(checkanswer($question_id,$users_answer) = "yes")
{
// they are correct so do what you need to here
}
else
{
// they are wrong so do what you need to here
}

?>
..hope this helps you out a bit.
Post Reply