คือผมดึงข้อมูลมาจากฐานข้อมูล testing ที่มีการเก็บ ข้อมูลต่างๆ รวมถึงเก็บ id_vdo ที่ดึงจากตารางอื่นมา แล้วผมเขียนไม่ได้เรื่องการดึงข้อมูลแบบทดสอบ ที่มีการกำหนดว่าเมื่อเข้าชมวีดีโอนี้แล้ว จะมีลิงค์แบบทดสอบ ของวีดีโอนั้นๆ ซึ่งที่ผมเขียนมานี้มันรันมาหมดทุกแบบทดสอบของวีดีโออื่นๆ ด้วย แล้วยังรันขึ้นมา 20 ข้อ ทั้งๆ ที่ผมกำหนด maxRows_Recordset1 = 10 ซึ่งผมเขียนไม่เก่งด้วย หรือใครมีวิธีอื่น ช่วยแนะนำหน่อยนะครับ
<?php require_once('Connections/Myconnect1.php'); ?>
<?php
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;
$colname_Recordset1 = "-1";
if (isset($_GET['id_vdo'])) {
$colname_Recordset1 = $_GET['id_vdo'];
}
mysql_select_db($database_Myconnect1, $Myconnect1);
$query_Recordset1 = sprintf("SELECT * FROM testing WHERE id_vdo = %s", GetSQLValueString($colname_Recordset1, "int"));
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $Myconnect1) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
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 http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form name="form1" method="post" action="test_ans.php">
<?php
$i=0;
while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
{
$i++;
?>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td><div ><input name="id[<?=$i;?>]"type="hidden" value="<?php $row_Recordset1['id']; ?>" />
<input name="id_vdo[<?=$i;?>" type="hidden" value="<?php $row_Recordset1['id_vdo']; ?>" />
<?php $row_Recordset1['question']; ?>
</div> </td>
<tr>
<td><input name="c[<?=$i;?>]" type="radio" value="1" /><?php $row_Recordset1['c1']; ?> </td>
</tr>
<tr>
<td><input name="c[<?=$i;?>]" type="radio" value="2"/><?php $row_Recordset1['c2']; ?> </td>
</tr>
<tr>
<td><input name="c[<?=$i;?>]" type="radio" value="3"/><?php $row_Recordset1['c3']; ?> </td>
</tr>
<tr>
<td><input name="c[<?=$i;?>]" type="radio" value="4"/><?php $row_Recordset1['c4']; ?>
<input name="answer[<?=$i;?>]" type="hidden" value="<?php $row_Recordset1['answer']; ?>" /></td>
<td></td>
</tr>
</table>
<?
}
mysql_close();
?>
<div align="center"><br>
<input type="submit" name="Submit" value="ตรวจคะแนน">
</div>
</form>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
ปล. ไม่รู้เข้าใจหรือเปล่า ขนาดผมยังงงเลย T_T
ถามเรื่องการเขียน Php แบบทดสอบ ที่ดึงมาจากฐานข้อมูล
<?php require_once('Connections/Myconnect1.php'); ?>
<?php
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;
$colname_Recordset1 = "-1";
if (isset($_GET['id_vdo'])) {
$colname_Recordset1 = $_GET['id_vdo'];
}
mysql_select_db($database_Myconnect1, $Myconnect1);
$query_Recordset1 = sprintf("SELECT * FROM testing WHERE id_vdo = %s", GetSQLValueString($colname_Recordset1, "int"));
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $Myconnect1) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
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 http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form name="form1" method="post" action="test_ans.php">
<?php
$i=0;
while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
{
$i++;
?>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td><div ><input name="id[<?=$i;?>]"type="hidden" value="<?php $row_Recordset1['id']; ?>" />
<input name="id_vdo[<?=$i;?>" type="hidden" value="<?php $row_Recordset1['id_vdo']; ?>" />
<?php $row_Recordset1['question']; ?>
</div> </td>
<tr>
<td><input name="c[<?=$i;?>]" type="radio" value="1" /><?php $row_Recordset1['c1']; ?> </td>
</tr>
<tr>
<td><input name="c[<?=$i;?>]" type="radio" value="2"/><?php $row_Recordset1['c2']; ?> </td>
</tr>
<tr>
<td><input name="c[<?=$i;?>]" type="radio" value="3"/><?php $row_Recordset1['c3']; ?> </td>
</tr>
<tr>
<td><input name="c[<?=$i;?>]" type="radio" value="4"/><?php $row_Recordset1['c4']; ?>
<input name="answer[<?=$i;?>]" type="hidden" value="<?php $row_Recordset1['answer']; ?>" /></td>
<td></td>
</tr>
</table>
<?
}
mysql_close();
?>
<div align="center"><br>
<input type="submit" name="Submit" value="ตรวจคะแนน">
</div>
</form>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
ปล. ไม่รู้เข้าใจหรือเปล่า ขนาดผมยังงงเลย T_T