- This topic is empty.
-
AuthorPosts
-
March 7, 2013 at 4:45 am #43212narasimharaoMember
i am writing php quiz application with timer and score will generated after submition of form.but my problem is form is not submited after complection of time
session_start();
$minutes = 1; // Enter minutes
$seconds = 0; // Enter seconds
$time_limit = ($minutes * 60) + $seconds + 1; // Convert total time into seconds
if(!isset($_SESSION[“start_time”])){$_SESSION[“start_time”] = mktime(date(G),date(i),date(s),date(m),date(d),date(Y)) + $time_limit;} // Add $time_limit (total time) to start time. And store into session variable.
?>
[script>
var ct = setInterval(“calculate_time()”,100); // Start clock.
function calculate_time()
{
var end_time = ““; // Get end time from session variable (total time in seconds).
var dt = new Date(); // Create date object.
var time_stamp = dt.getTime()/1000; // Get current minutes (converted to seconds).
var total_time = end_time – Math.round(time_stamp); // Subtract current seconds from total seconds to get seconds remaining.
var mins = Math.floor(total_time / 60); // Extract minutes from seconds remaining.
var secs = total_time – (mins * 60); // Extract remainder seconds if any.
if(secs < 10){secs = "0" + secs;} // Check if seconds are less than 10 and add a 0 in front.
document.getElementById(“txt”).value = mins + “:” + secs; // Display remaining minutes and seconds.
// Check for end of time, stop clock and display message.
if(mins <= 0)
{
if(secs <= 0 || mins < 0)
{
clearInterval(ct);
document.getElementById(“txt”).value = “0:00”;
document.f1.submit();
alert(“The time is up.”);
}
}
}include(“connection.php”);
$display = mysql_query(“SELECT * FROM tbl_questions ORDER BY Qno “);
if (!@$_POST) {
echo “
“;
}else if($_POST)
{//echo”executed”;
$score = 0;
$total = mysql_num_rows($display);while ($result = mysql_fetch_array($display)) {
$answer = $result[“answer”];
$id = $result[“Qno”];
$or=q.$id;
//echo”$or”;if ($_POST[$or] == $answer) {
$score++;
}}
echo “
You scored $score out of $total
“;
}?>
March 7, 2013 at 6:32 am #127298CrocoDillonParticipantDo you have a live demo? Codepen?
Does this gives you an error? `[script>`
And this? `document.f1.submit();` (I think it should be `document.forms.f1.submit();`)
March 7, 2013 at 6:46 am #127302Paulie_DMember>Does this gives you an error? [script>
That was me…I had to change < to [ so it would render correctly on the forum.
March 7, 2013 at 6:50 am #127306narasimharaoMemberthank you,actually in my code have some html tags in the above code don’t have any html code it is not working…
March 7, 2013 at 7:14 am #127308CrocoDillonParticipantOh lol @Paulie_D :P
`document.forms.f1.submit();` or live demo / codepen.
April 4, 2013 at 1:05 am #130597ankit88Participanti am using the same code in my online quiz…but the problem is that i want take time difference in minute and second format…and that difference i want to store in database(i.e. it user starts at 15.00 min and ends at 13.00 min the the difference will be 2 min, this value i want to store in database )……….how can i do that please provide me some code for solving this problem…..?????????
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.