Я показываю страницу со всеми записями студентов вместе с флажком в каждой строке. У меня также есть флажок в <TABLE>
THEAD, чтобы выбрать / отменить выбор ВСЕХ строк. Я получаю записи с mySQL при выборе КУРСА из выпадающего списка, используя AJAX.
- После заполнения
<TABLE>
выбор / отмена выбора не работает. Даже после выбора необходимых строк вручную это не отражается на странице PHP, и это всегда говорит о том, что я выбрал только ОДИН ряд. Вот мой полный HTML код и PHP страницы для ознакомления.
$rID = $_SESSION["regionID"];
$zID = $_SESSION["zoneID"];
$utype = $_SESSION["usertype"];
$cID = $_SESSION["centreID"];
include_once("middletier\config.php");
if($utype == 0 || $utype == 4)
{
?> <?php include_once('header.php');?>
<style type="text/css">
.modal-tall .modal-dialog {
height: 70%;
}
.modal-tall .modal-content {
height: 100%;
}
</style>
<?php include_once('profilemenu.php'); ?>
<div class="site-content">
<div class="content-area py-1">
<div class="container-fluid">
<div class="box box-block bg-white">
<form name="students2exam" action="middletier\updatestudents2exam.php" method="post"/>
<div class="row" >
<div class="col-lg-2">
<label for="centreID">Course:</label>
</div>
<div class="col-lg-4">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-envelope"></i></span>
<?php
switch($utype)
{
case 3:
case 0:
case 4: $sql = "select b.course2zoneID,a.courseID, a.courseName, a.courseTypeID, d.courseType, b.zoneID, c.zoneName, e.regionName, concat(a.courseName,' [', d.courseType ,' ]') as 'course' from coursemaster a, course2zone b, zonemaster c, coursetypemaster d, regionmaster e where b.zoneID=$zID and a.courseID = b.courseID and b.zoneID = c.zoneID and a.courseTypeID = d.courseTypeID and c.regionID = e.regionID and c.regionID=$rID and a.activeFlag=1 and a.delFlag=0 and b.delFlag=0 and c.delFlag=0 and d.delFlag=0 and e.delFlag=0 order by a.courseName";break;
}
$results = mysqli_query($conn, $sql);
if (mysqli_num_rows($results) > 0)
{
while ( $row = mysqli_fetch_array ($results,MYSQLI_ASSOC));
}
?>
<select name="courseID" id="courseID" class="form-control" required">
<option selected value=-1>Select Course</option>
<?php
if (mysqli_num_rows($results) >0)
{
foreach ($results as $row){
echo "<option value=$row[courseID]>$row[course]</option>";
}
}
?>
</select>
</div>
</div>
</div>
<hr style="height: 2px;background: black; " >
<!--<div id="table2">
</div>-->
<table class="table table-striped table-bordered" width="100%">
<thead>
<tr style="font-size:12px;text-align:center">
<th style="text-align:center"><input type="checkbox" style="text-align:center" id="select_all" value=""/></th>
<th style="font-size:12px;text-align:center">Regn No.</th>
<th style="font-size:12px;text-align:center">Student Name</th>
<th style="font-size:12px;text-align:center">Address</th>
<th style="font-size:12px;text-align:center">Course</th>
<th style="font-size:12px;text-align:center">Exam Date</th>
</tr>
</thead>
<tbody id="table2">
</tbody>
</table>
<br/>
<div class="row">
<div class="col-lg-2">
<label style="font-size:12px;text-align:left">Exam Centre:</label>
</div>
<div class="col-lg-10" style="text-align:left">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-envelope"></i></span>
<?php
$sql = "select a.examcentreID, a.examcentre, a.centreaddress, concat(a.examcentre,' [', a.centreaddress,' ]') as address, a.landmark, a.regionID, c.regionName, a.zoneID, b.zoneName, a.contactperson, a.contactno from examcentres a, zonemaster b, regionmaster c where a.zoneID=b.zoneID and b.regionID=c.regionID and a.delFlag=0 and b.delFlag=0 and c.delFlag=0 and a.regionID=b.regionID and a.regionID=$rID and a.zoneID=$zID order by a.examcentre";
$results = mysqli_query($conn, $sql);
if (mysqli_num_rows($results) > 0)
{
while ( $row = mysqli_fetch_array ($results,MYSQLI_ASSOC));
}
?>
<select name="examcentreID" id="examcentreID" required class="form-control">
<option selected value=-1>Select Exam Centre</option>
<?php
if (mysqli_num_rows($results) >0)
{
foreach ($results as $row){
echo "<option value=$row[examcentreID]>$row[address]</option>";
}
}
?>
</select>
</div>
</div>
</div>
<br/>
<div class="row">
<div class="col-lg-2">
<label style="font-size:12px;text-align:left">Exam Date:</label>
</div>
<div class="col-lg-3" style="text-align:left">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-envelope"></i></span>
<select name="examDateID" id="examDateID" required class="form-control">
</select>
</div>
</div>
</div>
<hr style="height: 2px;background: black; " >
<input type="submit" name="submit" id="submit" value="Submit" class="btn btn-primary">
</form>
</div>
<script>
$(document).ready(function(){
$('#select_all').on('click',function(){
if(this.checked){
$('.checkbox').each(function(){
this.checked = true;
});
}else{
$('.checkbox').each(function(){
this.checked = false;
});
}
});*/
$('.checkbox').on('click',function(){
if($('.checkbox:checked').length == $('.checkbox').length){
$('#select_all').prop('checked',true);
}else{
$('#select_all').prop('checked',false);
}
});
});
$ (документ) .ready ( function () {$ ("# courseID"). change (function () {var courseID = $ ("# courseID"). val (); $. ajax ({тип: "POST", URL: "middletier") /getStudents.php ", data: 'courseID =' + courseID}). done (function (data) {$ (" # table2 "). html (data); $.ajax({
type: "POST",
url: "middletier/getExamDates.php",
data:'courseID='+courseID
}).done(function(data){
$("#examDateID").html(data);
});
});
});
});
/ * getStudents. php * /
<?php
session_start();
if ($_POST)
{
if(isset($_POST['courseID']))
{
include "config.php";
$courseID = $_POST['courseID'];
$rID = $_SESSION["regionID"];
$zID = $_SESSION["zoneID"];
$utype = $_SESSION["usertype"];
$cID = $_SESSION["centreID"];
$output="";
$sql = "select IFNULL(FIRST.studentID,SECOND.studentID) as 'studentID',IFNULL(FIRST.student2coursemapID,SECOND.student2coursemapID) as 'student2coursemapID',IFNULL(FIRST.courseID,SECOND.courseID) as 'courseID', IFNULL(FIRST.address,SECOND.address) as 'address', IFNULL(FIRST.regnNo,SECOND.regnNo) as 'regnNo', IFNULL(FIRST.studentName,SECOND.studentName) as 'studentName', IFNULL(FIRST.studentSKTName,SECOND.studentSKTName) as 'studentSKTName', IFNULL(FIRST.course,SECOND.course) as 'course', IFNULL(FIRST.student2examID,0) as 'student2examID', IFNULL(FIRST.examDate,'') as 'examDate' from (select a.studentID, b.student2coursemapID, a.courseID, a.reexamflag, b.courseTypeID, b.feesPaid, a.student2examID, concat(c.street,',', c.road,',', c.city) as 'address', c.contactno, c.regnNo, c.studentName, c.studentSKTName, concat(d.courseName,' [',e.courseType,' ]') as 'course', f.examDate from student2exam a, student2coursemap b, studentmaster c, coursemaster d, coursetypemaster e, examdatemaster f where a.studentID=b.studentID and a.courseID=b.courseID and a.examDateID=f.examDateID and a.courseID=d.courseID and b.courseID=d.courseID and b.courseTypeID=d.courseTypeID and d.courseTypeID=e.courseTypeID and a.courseID=f.courseID and a.studentID=c.studentID and f.courseID=b.courseID and f.examDate>=now() and f.regionID=c.regionID and c.regionID=$rID and f.zoneID=c.zoneID and c.zoneID=$zID and f.centreID=c.centreID and c.centreID=$cID and a.delFlag=0 and b.delFlag=0 and c.delFlag=0 and d.delFlag=0 and e.delFlag=0 and f.delFlag=0 and b.courseID=$courseID) as FIRST RIGHT JOIN (select b.studentID, b.student2coursemapID, b.courseID, b.courseTypeID, b.feesPaid, concat(c.street,',', c.road,',', c.city) as 'address', c.contactno, c.regnNo, c.studentName, c.studentSKTName, concat(d.courseName,' [',e.courseType,' ]') as 'course' from student2coursemap b, studentmaster c, coursemaster d, coursetypemaster e where b.studentID=c.studentID and b.courseID=d.courseID and b.courseTypeID=d.courseTypeID and d.courseTypeID=e.courseTypeID and c.regionID=$rID and c.zoneID=$zID and c.centreID=$cID and b.delFlag=0 and c.delFlag=0 and d.delFlag=0 and e.delFlag=0 and b.courseID=$courseID) as SECOND on FIRST.studentID=SECOND.studentID";
$result = mysqli_query($conn,$sql);
if(!empty($result))
{
while( $row = mysqli_fetch_array($result,MYSQLI_ASSOC) )
{
$output.='<tr style="height: 10px;line-height: 10px;min-height: 10px;">';
if($row["student2examID"]==0)
$output.='<td align="center"><input type="checkbox" name="checked_id[]" class="checkbox" value="' .$row["studentID"]. '"/></td>';
else
$output.='<td align="center"><input type="checkbox" name="checked_id[]" class="checkbox" checked value="' .$row["studentID"]. '"/></td>';
$output.='<td style="font-size:12px;text-align:left">'.$row["regnNo"].'</td>
<td style="font-size:12px;text-align:left">'.$row["studentName"].'</td>
<td style="font-size:12px;text-align:left">'.$row["address"].'</td>
<td style="font-size:12px;text-align:left">'.$row["course"].'</td>
<td style="font-size:12px;text-align:left">'.$row["examDate"].'</td>
<input type="hidden" value='.$row["student2examID"].' id="student2examID" name="student2examID">
</tr>';
}
}
echo $output;
}
else {
header('location: ./');
}
}
else
{
echo "error";
exit;
}
?>
/ updatestudent. php /
<?php
session_start();
if(isset($_SESSION["userID"]))
{
$userID = $_SESSION["userID"];
$rID = $_SESSION["regionID"];
$zID = $_SESSION["zoneID"];
$utype = $_SESSION["usertype"];
$cID = $_SESSION["centreID"];
include_once("config.php");
if(isset($_POST["submit"]) && $_POST["submit"]!="")
{
if(isset($_POST["checked_id"]))
{
$courseID = mysqli_real_escape_string($conn, $_POST["courseID"]);
$examcentreID = mysqli_real_escape_string($conn, $_POST["examcentreID"]);
$examDateID = mysqli_real_escape_string($conn, $_POST["examDateID"]);
$studID =array();
$studID=$_POST["checked_id"];
$studCount = count($studID);
$i=0;
for($i=0;$i<$studCount;$i++)
{
$studentID = $studID[$i];
$query = "INSERT INTO student2exam(studentID, courseID,examDateID,examcentreID,reexamflag,lastUpdatedOn,lastUpdatedBy,delFlag) VALUES($studentID,$courseID,$examDateID,$examcentreID,0,now(),$userID,0);";
$message = 'Data Inserted';
}
if(mysqli_query($conn, $query))
{
header('location: ../studentsforexam.php');
}
}
}
}
?>