|
|
|
ต้องการให้มีการฟ้องว่าห้องสอบเต็มแล้วในกรณีที่จัดที่นั่งในห้องนั้นเต็มตามจำนวนที่กำหนดแล้วครับ (มีโีค๊ดและรูปครับ) |
|
|
|
|
|
|
|
สวัสดีครับทุก ๆ ท่าน
พอดีว่าผมพัฒนาโปรแกรมต่อจากคนก่อนหน้านี้ ทั้งนี้เป็นระบบเกี่ยวกับการสมัครเรียนซึ่งในกระทู้นี้ผมอยากรบกวนให้่ช่วยดูการเพิ่มโค๊ดในส่วนที่เป็นข้อความแจ้งเตือนขึ้นมาในกรณี แอดมินจะจัดคนเข้าห้องสอบที่เต็มอัตราแล้ว ว่า "ห้องสอบเต็มแล้วกรุณาตรวจสอบห้องสอบ" เช่น
ห้องสอบ A สามารถนั่งได้ 50 ที่นั่ง และเมื่อครบแล้ว แต่แอดมินไปเพิ่มคนที่ 51 เข้าไป ระบบจะฟ้องว่า "ห้องสอบเต็มแล้วกรุณาตรวจสอบห้องสอบ" ประมาณนี้ครับ
เรื่องห้องสอบนั้นได้จัดทำเสร็จแล้วตอนนี้ขอแค่แทรกโค๊ดเข้าไปครับ ดังนี้
โค๊ดห้องสอบครับ
<?php
require_once("tool.inc.php");
class ExamRoom extends Tool{
var $TbExamRoom = "tu_exam_room";
var $TbSeat = "tu_exam_room2candidate";
//////////////////////////////////////////////////////////////
// //
// Exam room area //
// //
//////////////////////////////////////////////////////////////
function Set($RoomName=NULL,$Description=NULL,$Seat=NULL,$ProjectID=NULL,$AccessUserID=NULL){
if(empty($RoomName) || !is_numeric($Seat) || !is_numeric($AccessUserID))return false;
$Field = "roomname,description,seat,projectid,creatoruserid,createdate";
$Value = "'".htmlspecialchars($this->CleanSQL($RoomName))."','".htmlspecialchars($this->CleanSQL($Description))."','$Seat','$ProjectID',$AccessUserID,NOW()";
require_once("dbconnect.inc.php");
$sql = "INSERT INTO ".$this->TbExamRoom." ($Field) VALUES($Value)";
mysql_query($sql) or die($sql." : ".mysql_errno()." -> ".mysql_error());
unset($sql,$Field,$Value);
return mysql_insert_id();
}//End Set
function Get($RoomID=NULL,$ProjectID=NULL,$RecordStart=NULL,$RecordPerPage=NULL){
$Field = "roomid,roomname,description,seat,projectid,creatoruserid,createdate,modifiedbyuserid,lastmodified";
$Condition = $ReturnResult = array();
if(is_numeric($RoomID)) $Condition[] = " roomid=$RoomID";
$sql = "SELECT $Field FROM ".$this->TbExamRoom;
if(count($Condition)) $sql .=" WHERE ".implode(" AND ",$Condition);
if(!empty($Order)) $sql .= " ORDER BY $Order";
if(is_numeric($RecordStart) AND is_numeric($RecordPerPage)) $sql .= " LIMIT $RecordStart,$RecordPerPage";
require_once("dbconnect.inc.php");
$result = mysql_query($sql) or die($sql." : ".mysql_errno()." -> ".mysql_error());
while($row= mysql_fetch_array($result)){
$Value = array();
for($index=0;$index<mysql_num_fields($result);$index++){
$Field = mysql_fetch_field($result,$index);
$Value[$Field->name] = $row[$Field->name];
}//End while
$ReturnResult[] = $Value;
}//End while
unset($sql,$Field,$Condition);
return $ReturnResult;
}//End Get
function Browse($RoomName=NULL,$Keyword=NULL,$Seat=NULL,$ProjectID=NULL,$RecordStart=NULL,$RecordPerPage=NULL){
$Field = "roomid,roomname,description,seat,projectid,creatoruserid,createdate,modifiedbyuserid,lastmodified";
$Condition = $ReturnResult = array();
if(is_numeric($RoomID)) $Condition[] = " roomid=$RoomID";
if(!empty($RoomName)) $Condition[] = " roomname='$RoomName%'";
if(!empty($Description)){
$x = explode(" ",$Description);
if(count($x)){
foreach($x as $Keyword ) $xCondition[] = " LOCATE('$Keyword',description) ";
$Condition[] = " ( ".implode(" or ",$xCondition)." ) ";
}else $Condition[] = " LOCATE('$Description',description)";
}//end if
if(!empty($Seat)) $Condition[] = " seat='$Seat'";
if(is_numeric($ProjectID)) $Condition[] = " projectid=$ProjectID";
$sql = "SELECT $Field FROM ".$this->TbExamRoom;
if(count($Condition)) $sql .=" WHERE ".implode(" AND ",$Condition);
if(!empty($Order)) $sql .= " ORDER BY $Order";
if(is_numeric($RecordStart) AND is_numeric($RecordPerPage)) $sql .= " LIMIT $RecordStart,$RecordPerPage";
require_once("dbconnect.inc.php");
$result = mysql_query($sql) or die($sql." : ".mysql_errno()." -> ".mysql_error());
while($row= mysql_fetch_array($result)){
$Value = array();
for($index=0;$index<mysql_num_fields($result);$index++){
$Field = mysql_fetch_field($result,$index);
$Value[$Field->name] = $row[$Field->name];
}//End while
$ReturnResult[] = $Value;
}//End while
unset($sql,$Field,$Condition);
return $ReturnResult;
}//End Browse
function Update($RoomID=NULL,$RoomName=NULL,$Description=NULL,$Seat=NULL,$ProjectID=NULL,$AccessUserID=NULL){
if(!is_numeric($RoomID) || empty($RoomName) || !is_numeric($AccessUserID))return false;
$Field = "roomname='".htmlspecialchars($this->CleanSQL($RoomName))."',description='".htmlspecialchars($this->CleanSQL($Description))."',seat='$Seat',modifiedbyuserid=$AccessUserID,lastmodified=NOW()";
if(!empty($ProjectID))$Field .= ",projectid='$ProjectID'";
$Condition = array();
if(is_numeric($RoomID)) $Condition[] = " roomid=$RoomID";
require_once("dbconnect.inc.php");
$sql = "UPDATE ".$this->TbExamRoom." SET $Field";
if(count($Condition)) $sql .=" WHERE ".implode(" AND ",$Condition);
mysql_query($sql) or die($sql." : ".mysql_errno()." -> ".mysql_error());
return true;
}//End Update
function Remove($RoomID=NULL,$AccessUserID=NULL){
if(!is_numeric($RoomID) || !is_numeric($AccessUserID))return false;
$Condition = array();
if(is_numeric($RoomID)) $Condition[] = " roomid=$RoomID";
$sql = "DELETE FROM ".$this->TbExamRoom;
if(count($Condition)) $sql .=" WHERE ".implode(" AND ",$Condition);
require_once("dbconnect.inc.php");
mysql_query($sql) or die($sql." : ".mysql_errno()." -> ".mysql_error());
unset($Condition,$sql);
return true;
}//End Remove
function CheckDruplicate($RoomID=NULL,$RoomName=NULL){
$Field = "roomid,roomname";
require_once("dbconnect.inc.php");
$Condition = array();
if(is_numeric($RoomID)) $Condition[] = " roomid!=$RoomID";
if(!empty($RoomName)) $Condition[] =" roomname='$RoomName'";
$sql = "SELECT $Field FROM ".$this->TbExamRoom;
if(count($Condition)) $sql .=" WHERE ".implode(" AND ",$Condition);
$result = mysql_query($sql) or die($sql." : ".mysql_errno()." -> ".mysql_error());
$ReturnResult = mysql_num_rows($result);
unset($sql,$Field,$Condition);
return $ReturnResult;
}//End CheckDruplicate
}//End ExamRoom
class ExamSeat extends Tool{
var $TbExamRoom = "tu_exam_room";
var $TbSeat = "tu_exam_room2seat";
var $TbCandidatePersonalInfo = "tu_candidate_personalinfo";
var $TbCandidateUser = "tu_candidate_user";
var $TbProject = "tu_project";
//////////////////////////////////////////////////////////////
// //
// Seat area //
// //
//////////////////////////////////////////////////////////////
function Set($RoomID=NULL,$SeatID=NULL,$CandidateID=NULL,$AccessUserID=NULL){
if(!is_numeric($RoomID) || !is_numeric($SeatID) || !is_numeric($CandidateID) || !is_numeric($AccessUserID))return false;
$Field = "roomid,seatid,candidateid,creatoruserid,createdate";
$Value = "'$RoomID','$SeatID',$CandidateID,$AccessUserID,NOW()";
$sql = "INSERT INTO ".$this->TbSeat." ($Field) VALUES($Value)";
require_once("dbconnect.inc.php");
mysql_query($sql) or die($sql." : ".mysql_errno()." -> ".mysql_error());
unset($sql,$Field,$Value);
return true;
}//End Set
function Set130110($RoomID=NULL,$SeatID=NULL,$CandidateID=NULL,$AccessUserID=NULL){
if(!is_numeric($RoomID) || !is_numeric($SeatID) || !is_numeric($CandidateID) || !is_numeric($AccessUserID))return false;
$Result = $this->Get(NULL,NULL,$CandidateID);
if(!count($Result)){
$Field = "roomid,seatid,candidateid,creatoruserid,createdate";
$Value = "'$RoomID','$SeatID',$CandidateID,$AccessUserID,NOW()";
require_once("dbconnect.inc.php");
$sql = "INSERT INTO ".$this->TbSeat." ($Field) VALUES($Value)";
mysql_query($sql) or die($sql." : ".mysql_errno()." -> ".mysql_error());
unset($sql,$Field,$Value);
return mysql_insert_id();
}else{
return $Result[0]["seatid"];
}//End if
}//End Set
function Get($RoomID=NULL,$SeatID=NULL,$CandidateID=NULL,$RecordStart=NULL,$RecordPerPage=NULL,$Order=NULL){
$Field = "roomid,seatid,candidateid,creatoruserid,createdate";
$Condition = $ReturnResult = array();
if(is_numeric($RoomID)) $Condition[] = " roomid=$RoomID";
if(is_numeric($SeatID)) $Condition[] = " seatid=$SeatID";
if(is_numeric($CandidateID)) $Condition[] = " candidateid=$CandidateID";
$sql = "SELECT $Field FROM ".$this->TbSeat;
if(count($Condition)) $sql .=" WHERE ".implode(" AND ",$Condition);
if(!empty($Order)) $sql .= " ORDER BY $Order";
if(is_numeric($RecordStart) AND is_numeric($RecordPerPage)) $sql .= " LIMIT $RecordStart,$RecordPerPage";
require_once("dbconnect.inc.php");
$result = mysql_query($sql) or die($sql." : ".mysql_errno()." -> ".mysql_error());
while($row= mysql_fetch_array($result)){
$Value = array();
for($index=0;$index<mysql_num_fields($result);$index++){
$Field = mysql_fetch_field($result,$index);
$Value[$Field->name] = $row[$Field->name];
}//End while
$ReturnResult[] = $Value;
}//End while
unset($sql,$Field,$Condition);
return $ReturnResult;
}//End Get
function GetAvailable($RoomID=NULL,$ProjectID=NULL){
$t2 = $this->TbSeat;
#no_row no_col
$SeatID = NULL;
$Field = "roomid,seat,projectid";
$Condition = $ReturnResult = array();
if(is_numeric($RoomID)) $Condition[] = " roomid=$RoomID";
if(is_numeric($ProjectID)) $Condition[] = " projectid=$ProjectID";
$sql = "SELECT $Field FROM ".$this->TbExamRoom;
if(count($Condition)) $sql .=" WHERE ".implode(" AND ",$Condition);
if(empty($Order)) $sql .= " ORDER BY roomid ASC";
if(is_numeric($RecordStart) AND is_numeric($RecordPerPage)) $sql .= " LIMIT $RecordStart,$RecordPerPage";
require_once("dbconnect.inc.php");
$result = mysql_query($sql) or die($sql." : ".mysql_errno()." -> ".mysql_error());
while($row= mysql_fetch_array($result)){
//====== Get existing seat in room ======//
$TotalSeat = $row["seat"];
$ReturnResult["roomid"]=$row["roomid"];
$Result = $this->Get($row["roomid"]);
if(count($Result)<$TotalSeat){
$SeatList = array();
if(count($Result)) foreach($Result as $ElementID=>$ElementValue) $SeatList[] = $ElementValue["seatid"];
for($i=0;$i<$TotalSeat;$i++){
if(!in_array($i,$SeatList)){
$SeatID = $ReturnResult["seatid"]= $i;
break;
}//End if
}//End for
if(is_numeric($SeatID)) break;
}//End if
}//End while
unset($sql,$Field,$Condition);
return $ReturnResult;
}//end GetAvailable
function GetCandidateNoSeat($RoomID=NULL,$ProjectID=NULL){
$t1 = $this->TbCandidateUser;
$t2 = $this->TbCandidatePersonalInfo;
$t3 = $this->TbSeat;
$Table = "$t1
LEFT JOIN $t2 ON $t2.candidateid=$t1.candidateid
LEFT JOIN $t3 ON $t3.candidateid=$t1.candidateid
";
$Condition = $ReturnResult = array();
$Condition[] = " $t1.candidateid=$t2.candidateid";
$Condition[] = " $t3.seatid IS NULL";
# if(is_numeric($RoomID)) $Condition[] = " roomid=$RoomID";
# if(is_numeric($SeatID)) $Condition[] = " seatid=$ProjectID";
# if(is_numeric($CandidateID)) $Condition[] = " candidateid=$CandidateID";
$Field = "
$t1.candidateid,$t1.applicantno,
CONCAT($t2.title,' ',$t2.firstname,' ',$t2.lastname) AS fullname,
$t3.seatid
";
$sql = "SELECT $Field FROM $Table";
if(count($Condition)) $sql .=" WHERE ".implode(" AND ",$Condition);
$sql .= " GROUP BY candidateid";
if(!empty($Order)) $sql .= " ORDER BY CONCAT($t2.firstname,$t2.lastname)";
if(is_numeric($RecordStart) AND is_numeric($RecordPerPage)) $sql .= " LIMIT $RecordStart,$RecordPerPage";
require_once("dbconnect.inc.php");
$result = mysql_query($sql) or die($sql." : ".mysql_errno()." -> ".mysql_error());
while($row= mysql_fetch_array($result)){
$Value = array();
for($index=0;$index<mysql_num_fields($result);$index++){
$Field = mysql_fetch_field($result,$index);
$Value[$Field->name] = $row[$Field->name];
}//End while
$ReturnResult[] = $Value;
}//End while
unset($sql,$Field,$Condition);
return $ReturnResult;
}//End GetCandidateNoSeat
function Browse($RoomID=NULL,$RoomName=NULL,$SeatID=NULL,$ApplicantNo=NULL,$Firstname=NULL,$Lastname=NULL,$ProjectID=NULL,$RecordStart=NULL,$RecordPerPage=NULL,$Order=NULL){
$t1 = $this->TbSeat;
$t2 = $this->TbCandidatePersonalInfo;
$t3 = $this->TbCandidateUser;
$t4 = $this->TbExamRoom;
$t5 = $this->TbProject;
$Table = "$t1
LEFT JOIN $t2 ON $t2.candidateid=$t1.candidateid
LEFT JOIN $t3 ON $t3.candidateid=$t1.candidateid
LEFT JOIN $t4 ON $t4.roomid=$t1.roomid
LEFT JOIN $t5 ON $t5.projectid=$t4.projectid
";
$Field = "
$t1.roomid,$t1.seatid,$t1.candidateid,$t1.creatoruserid,$t1.createdate,
$t2.title,$t2.firstname,$t2.lastname,
$t3.applicantno,$t4.roomname,$t5.projectname,$t5.projectid
";
$Condition = $ReturnResult = array();
if(is_numeric($RoomID)) $Condition[] = " $t1.roomid=$RoomID";
if(is_numeric($SeatID)) $Condition[] = " $t1.seatid=$SeatID";
if(is_numeric($CandidateID)) $Condition[] = " $t1.candidateid=$CandidateID";
if(!empty($ApplicantNo)) $Condition[] = " $t3.applicantno='$ApplicantNo'";
if(!empty($Firstname)) $Condition[] = " $t2.firstname LIKE '$Firstname%'";
if(!empty($Lastname)) $Condition[] = " $t2.lastname LIKE '$Lastname%'";
$sql = "SELECT $Field FROM $Table";
if(count($Condition)) $sql .=" WHERE ".implode(" AND ",$Condition);
if(!empty($Order)) $sql .= " ORDER BY $Order";
else $sql .= " ORDER BY seatid ASC";
if(is_numeric($RecordStart) AND is_numeric($RecordPerPage)) $sql .= " LIMIT $RecordStart,$RecordPerPage";
require_once("dbconnect.inc.php");
$result = mysql_query($sql) or die($sql." : ".mysql_errno()." -> ".mysql_error());
while($row= mysql_fetch_array($result)){
$Value = array();
for($index=0;$index<mysql_num_fields($result);$index++){
$Field = mysql_fetch_field($result,$index);
$Value[$Field->name] = $row[$Field->name];
}//End while
$ReturnResult[] = $Value;
}//End while
unset($sql,$Field,$Condition);
return $ReturnResult;
}//End Browse
function Update($RoomID=NULL,$SeatID=NULL,$SeatName=NULL,$AccessUserID=NULL){
if(!is_numeric($RoomID) || !is_numeric($SeatID) || empty($SeatName) || !is_numeric($AccessUserID))return false;
$Field = "roomid='$RoomID',choicename='".htmlspecialchars($this->CleanSQL($SeatName))."',modifiedbyuserid=$AccessUserID,lastmodified=NOW()";
$Condition = $ReturnResult = array();
if(is_numeric($SeatID)) $Condition[] = " choiceid=$SeatID";
require_once("dbconnect.inc.php");
$sql = "UPDATE ".$this->TbSeat." SET $Field";
if(count($Condition)) $sql .=" WHERE ".implode(" AND ",$Condition);
mysql_query($sql) or die($sql." : ".mysql_errno()." -> ".mysql_error());
return true;
}//End Update
function Remove($RoomID=NULL,$SeatID=NULL,$AccessUserID=NULL){
if((!is_numeric($RoomID) && !is_numeric($SeatID)) || !is_numeric($AccessUserID))return false;
$Condition = array();
if(is_numeric($RoomID)) $Condition[] = "roomid=$RoomID";
if(is_numeric($SeatID)) $Condition[] = "seatid=$SeatID";
$sql = "DELETE FROM ".$this->TbSeat;
if(count($Condition)) $sql .=" WHERE ".implode(" AND ",$Condition);
require_once("dbconnect.inc.php");
mysql_query($sql) or die($sql." : ".mysql_errno()." -> ".mysql_error());
unset($Condition,$sql);
return true;
}//End Remove
}//End ExamSeat
?>
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2011-10-10 15:53:06 |
By :
narak0001 |
View :
1002 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แนวคิดก็อาจจะทำการเช็คก่อนจะใส่ลงไปใน database ว่ามันเต็มหรือยังถ้าเต็มแล้วก็ส่งค่ากลับว่า "ระบบเต็มแล้ว"
mysql_num_rows()
|
|
|
|
|
Date :
2011-10-10 21:44:52 |
By :
oxygenyoyo |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผมต้องแทรกโค๊ดส่วนที่แนะนำมาในบรรทัดไหนครับท่าน
|
|
|
|
|
Date :
2011-10-12 08:56:57 |
By :
narak0001 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|