Jump to content

Avoiding a timer reset?


Kane250

Recommended Posts

Hi,

 

I'm working on a quiz game that has a 10 second timer, after which the page is set to redirect to the next question after 10 seconds as well. However, I also have some php going on which makes text appear after people answer questions in text boxes after POST (which essentially reloads the page, and restarts the timer).

 

Any idea how I can rework the timer so it just disappears after POST is submitted?

 

Here is my code in case it helps.

 

<html>
<head>

<meta http-equiv="refresh" content="10;url=imagetest2.php">

<script type="text/javascript" src="CountDown.js"></script>
<script type="text/javascript">
window.onload=WindowLoad;
function WindowLoad(event) {
ActivateCountDown("CountDownPanel", 10);
}
</script>
<style type="text/css">
#CountDownPanel {color: blue; background-color: yellow; font-size: 18px;}
</style>

</head>


<body>

<img src="/images/imagetest1.png"><br />

Time remaining: <span id="CountDownPanel"></span>

<?php

//CONNECT TO MYSQL & THE DATABASE
$link = mysql_connect('localhost', 'user', 'pw');

$dbselected = mysql_select_db('user', $link);

//SELECT STATEMENT TO GET RANDOM DATA
$randomselect = mysql_query("SELECT highlowincome FROM responses ORDER BY RAND() LIMIT 0,1;") or die (mysql_error());

//SET VARIABLES FOR THE USERS RESPONSE AND THE RANDOM RESPONSES
$userresponse = $_POST['userresponse'];

$res = mysql_fetch_assoc($randomselect);
$randomanswer = $res['highlowincome'];

//PRINT OUT THE RESPONSE USING BOTH VARIABLES
print "<pre>";
print "Your Response: <b>$userresponse</b> Associates Most With Those Of <b>$randomanswer</b>.";
print "</pre>";

?>

<form method="POST" action="imagetest1.php" />
<input type='text' value="" name="userresponse" /><br />
<br />
<input type='submit' value="Submit Answer" name="submit" /><br />
</form>

<a href="imagetest2.php">Next Image</a>

</body>
</html>

 

Really appreciate any help you can offer...I'm so stuck on this one!

Link to comment
Share on other sites

That's along the lines of something I'm looking for, but I still don't know what the code should be. Since POST reloads the page, I want the timer to either stop in place or disappear on reload rather than restart its countdown...

 

Thanks!

Link to comment
Share on other sites

just put the

if($_SERVER['REQUEST_METHOD'] != "POST")

around anything you don't want to happen when there is a post....

 

<html>
<head>

<meta http-equiv="refresh" content="10;url=imagetest2.php">
<?php if($_SERVER['REQUEST_METHOD'] != "POST") { ?>
<script type="text/javascript" src="CountDown.js"></script>
<script type="text/javascript">
window.onload=WindowLoad;
function WindowLoad(event) {
ActivateCountDown("CountDownPanel", 10);
}
</script>
<style type="text/css">
#CountDownPanel {color: blue; background-color: yellow; font-size: 18px;}
</style>
<?php } ?>

</head>


<body>

<img src="/images/imagetest1.png"><br />

<?php
if($_SERVER['REQUEST_METHOD'] != "POST")
  print 'Time remaining: <span id="CountDownPanel"></span>';

//CONNECT TO MYSQL & THE DATABASE
$link = mysql_connect('localhost', 'user', 'pw');

$dbselected = mysql_select_db('user', $link);

//SELECT STATEMENT TO GET RANDOM DATA
$randomselect = mysql_query("SELECT highlowincome FROM responses ORDER BY RAND() LIMIT 0,1;") or die (mysql_error());

//SET VARIABLES FOR THE USERS RESPONSE AND THE RANDOM RESPONSES
$userresponse = $_POST['userresponse'];

$res = mysql_fetch_assoc($randomselect);
$randomanswer = $res['highlowincome'];

//PRINT OUT THE RESPONSE USING BOTH VARIABLES
print "<pre>";
print "Your Response: <b>$userresponse</b> Associates Most With Those Of <b>$randomanswer</b>.";
print "</pre>";

?>

<form method="POST" action="imagetest1.php" />
<input type='text' value="" name="userresponse" /><br />
<br />
<input type='submit' value="Submit Answer" name="submit" /><br />
</form>

<a href="imagetest2.php">Next Image</a>

</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.