I have jquery which print the remaining time of quiz to my page. It works fine. Now I want to put condition if else to output of timer_check.php's output. I have put condition if remaining time = 0 then echo timeout else print remaining time. My jquery is in quiz.php page. I want to check if output come from timer_check.php is timeout then All answer should submit to database else print remaining time in tableHolder div. So my question is how to put if else condition for output come from timer_check.php to quiz.php to check submit the quiz or print remaining time?
$(document).ready(function() {
refreshTable();
});
function refreshTable(){
$('#tableHolder').load('timer_check.php', function(){
setTimeout(refreshTable, 1000);
});
}
timer_check.php
session_start();
include("database.php");
$sql = "select * from ctip_test where test_id = '$_SESSION[testid]'";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
$starttime = $row['attemp_time'];
}
$datetime1 = new DateTime($starttime);
$datetime1->add(new DateInterval('P0Y0M0DT2H0M0S'));
$currenttime =date('Y-m-d H:i:s');
$datetime2 = new DateTime($currenttime);
$diff = $datetime2->diff($datetime1);
$check_timeout = (array) $datetime2->diff($datetime1);
$hour = $check_timeout['h'];
$minute = $check_timeout['i'];
$second = $check_timeout['s'];
if($hour=="0" && $minute =="0" && $second =="0"){
echo "time out";
}
else{
echo($diff->format("%h hours %i minutes and %s seconds are remaining
"));
}