|
|
|
ต้องการสร้างเวลาตอนที่ทำแบบทดสอบ แล้วเวลารีเฟสโปรแกรมเวลายังคงดำเนินต่อไปโดยที่ไม่เริ่มนับใหม่ |
|
|
|
|
|
|
|
Code (PHP)
<?php
session_start();
require_once('../Connections/MyConnec.php');
$u=$_SESSION["User_name"];//เปิด SESSION มาจากcheck_login
if (!function_exists("GetSQLValueString"))
{
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6)
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType)
{
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$maxRows_Recordset1 = 10;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1']))
{
$pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;
//$query_Recordset1 = "SELECT * FROM test ORDER BY Rand() ASC";
//$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
//$Recordset1 = mysql_query($query_limit_Recordset1, $MyConnec) or die(mysql_error());
//$row_Recordset1 = mysql_fetch_assoc($Recordset1);
/*
$chNum=0;
$selectSub=mysql_query("SELECT * FROM subject"); // select แต่ละวิชาออกมาแสดง
while($sub=mysql_fetch_array($selectSub))
{
$selectQue=mysql_query("SELECT * FROM test WHERE Sub_id='".$sub['Sub_id']."' ORDER BY rand() LIMIT 5"); // select คำถามแต่ละวิชา อ้างอิงจาก Sub_id แบบ Random limit 3
// $chNum=0;
while($row_Recordset1=mysql_fetch_array($selectQue))
{ $chNum++;
*/
/* if (isset($_GET['totalRows_Recordset1'])) {
$totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
$all_Recordset1 = mysql_query($query_Recordset1);
$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
}
*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>แบบทดสอบสมรรถนะวิชาชีพ</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body bgcolor="#FFFACD" onLoad="begintimer()">
<div class="row">
<div class="col-md-2"></div>
<div class="col-md-8">
<table border="1">
<tr><td align="center">
<p id="display"></p>
<script language="">
var limit="60:00"//คำสั่งการประกาศค่าตัวแปรเวลาเริ่มต้น
if (document.images)
{
var parselimit=limit.split(":");
parselimit=parselimit[0]*60+parselimit[1]*1;//หาค่าวินาที
}
function begintimer()
{
if (!document.images)
return
if (parselimit==1)
// เหตุการณ์ที่ต้องการให้เกิดขึ้น
// window.location='page.php'; ถ้าต้องการให้กระโดดไปยัง Page อื่น
frmTest.submit();
else
{
parselimit-=1;
curmin=Math.floor(parselimit/60);//คำนวณค่าวินาที วินาที/60นาที
cursec=parselimit%60;
if (curmin!=0)
curtime="เวลาที่เหลือ <font color=red> "+curmin+" </font>นาที กับ <font color=red>"+cursec+" </font>วินาที ";
else
if(cursec==0)
{
alert('หมดเวลาแล้วจ้า');
}
else
{
curtime="เวลาที่เหลือ <font color=red>"+cursec+" </font>วินาที ";
}
document.getElementById('display').innerHTML = curtime;
setTimeout("begintimer()",1000);
}
}
</script>
</td></tr>
<tr><td>
<?php
$chNum=0;
mysql_select_db($database_MyConnec, $MyConnec);
$selectSub=mysql_query("SELECT * FROM subject"); // select แต่ละวิชาออกมาแสดง
while($sub=mysql_fetch_array($selectSub))
{
$selectQue=mysql_query("SELECT * FROM test WHERE Sub_id='".$sub['Sub_id']."' ORDER BY rand() LIMIT 5"); // select คำถามแต่ละวิชา อ้างอิงจาก Sub_id แบบ Random limit 3
// $chNum=0;
while($row_Recordset1=mysql_fetch_array($selectQue))
{ $chNum++;
?>
<!--<div align="center"><img src="หัวเว็บ.png" alt="" width="1113" height="203" /></div>-->
<form id="frmTest" name="frmTest" method="post" action="get-answer.php">
<input type="hidden" name="St_User" value="<?php echo $u; ?>">
<p>
<?php
// $chNum=1;
// do {
?>
<br/>
<?php echo $chNum; ?>)<?php echo $row_Recordset1['T_question']; ?><br/><br/>
<input type="radio" name="<?php echo $row_Recordset1['T_id']; ?>" id="T_c1" value="1" />
<?php echo $row_Recordset1['T_c1']; ?><br />
<input type="radio" name="<?php echo $row_Recordset1['T_id']; ?>" id="T_c2" value="2" />
<?php echo $row_Recordset1['T_c2']; ?><br />
<input type="radio" name="<?php echo $row_Recordset1['T_id']; ?>" id="T_c3" value="3" />
<?php echo $row_Recordset1['T_c3']; ?><br />
<input type="radio" name="<?php echo $row_Recordset1['T_id']; ?>" id="T_c4" value="4" />
<input type="hidden" name="SS" value="<?php echo $row_Recordset1['Sub_id']; ?>" />
<?php echo $row_Recordset1['T_c4']; ?><br/></div>
</div>
<?php
}
}
// $chNum++;
// } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
?>
</p>
</td></tr>
</table>
</div>
<div class="col-md-2"></div>
</div>
<div class="container">
<ul class="pager">
<li class="previous"><a href="#">Previous</a></li>
<li class="next"><a href="#">Next</a></li>
</ul>
</div>
<p>
<center> <input type="submit" name="button" id="button" class="btn btn-info btn-block" value="ตกลง" " /></center>
<br>
</p>
</form>
<p> </p>
</body>
</html>
<?php
@mysql_free_result($Recordset1);
?>
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2017-05-28 16:26:23 |
By :
Tarnikar |
View :
731 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ใช้ session เก็บเวลา
|
|
|
|
|
Date :
2017-05-28 20:48:27 |
By :
mr.v |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|