I have a code that limits the checkbox selected. Then i have this pagination that i create manually. By means that i use some calculation and stuff. Ok now whenever i test the system like i select 2 checkbox in first page, 1 checkbox on the second page, it seems that, my limitations not activate. Unless i didn't change my page. For example if i select 3 checkbox on the same page, then my limitions show an alert that i have reach my max selected checkbox. Then why it wont work on the second page and stuff?
so this is my ajax code. the bottom part of it is my limitations checkbox code
function ajaxSearchUpdater(p){
$("#result").show();
var x = $("#search").val();
var y = $("#edulevel").val();
var pagelim = $("#pagefpe").val();
var pagenumber = p;
var checkb = $(".sBorrow").val()
$.ajax({
type:'POST',
url:'userres.php',
data:'q='+x+'&e='+y+'&pagelim='+pagelim+'&pageno='+pagenumber+'&checkb='+checkb,
cache:false,
success:function(data){
$("#result").html(data)
}
});
}
function setsession(sessionid,action){
$("#totalselection").show();
$.ajax({
type:'POST',
url:'test.php',
data:'sBorrow='+sessionid+'&action='+action,
cache:false,
success:function(data){
var out = "<p align='center' style='text-decoration:none;color:white;'>Total Selection: "+data+"<br/>Click here to submit your request <a href='borrowform.php?subid=borrow' id='submitborrow' name='submitborrow' style='text-align:center;'><input type='button' value='REQUEST' id='submitborrow' name='submitborrow'></a> || Click here to clear the selection <a href='#' style='text-align:center;'><input type='button' value='CLEAR'></a></p>";
$("#totalselection").html(out)
if(isset($_GET['subid'])){
alert('Please select any book first');
}
}
});
}
$(document).ready(function(e) {
ajaxSearchUpdater(1); // fires on document.ready
$("#search").keyup(function() {
ajaxSearchUpdater(1); // your function call
});
$("#edulevel").click(function() {
ajaxSearchUpdater(1); // your function call
});
$("#pagefpe").click(function() {
ajaxSearchUpdater(1); // your function call
});
$(document).delegate('.sBorrow', 'change', function(){
var sBorrowClass = $(this).attr('class');
var sBorrowValue = $(this).attr('value');
var sBorrowName = $(this).attr('name');
var sBorrowChecked = $(this).attr('checked');
var checked = this.checked;
var checkedCbs = $('.sBorrow:checked');
if (checkedCbs.length === 4) {
alert("You can only select 3 books");
this.checked = false;
}
if(checked){
setsession(sBorrowValue, "SET");
}
else{
setsession(sBorrowValue, "UNSET");
}
})
});
Here is my php file.
if($_POST['e'] == "ALL"){
$selector = "SELECT * FROM viewlibrary";
}
else{
$selector = "SELECT * FROM viewlibrary WHERE thesis_level = :e";
}
$pageno = $_POST['pageno'];
$totalrow="SELECT abc.*
FROM (".$selector.")abc
WHERE
abc.studentname LIKE :q OR
abc.matricno LIKE :q OR
abc.title LIKE :q OR
abc.year LIKE :q OR
abc.thesis_level LIKE :q OR
abc.programme LIKE :q OR
abc.serialno LIKE :q ";
$stmt2 = $db->prepare($totalrow);
$stmt2->bindValue(':q','%'.$q.'%');
$stmt2->bindValue(':e',$e);
$stmt2->execute();
//var_dump($row);
$row = $stmt2->rowCount();
echo "<div style='text-align:center;color:#FFFFFF;margin:3px;'>Result found: ".$row."</div>";
$limitrow = 1;
if(isset($_POST['pagelim'])){
$limitrow = $_POST['pagelim'];
if($limitrow == 0){
$limitrow = $row;
}
}
if($row != 0){
$baki = $row%$limitrow;
}
else{
$baki = 0;
$limitrow = 1;
$row = 1;
}
$maxpage = (($row-$baki)/$limitrow);
$startrow = $limitrow*($pageno-1);
if($baki!=0)
$maxpage++;
$query="SELECT abc.*
FROM (".$selector.")abc
WHERE
abc.studentname LIKE :q OR
abc.matricno LIKE :q OR
abc.title LIKE :q OR
abc.year LIKE :q OR
abc.thesis_level LIKE :q OR
abc.programme LIKE :q OR
abc.serialno LIKE :q
LIMIT ".$startrow.",".$limitrow;
$stmt = $db->prepare($query);
$stmt->bindValue(':q','%'.$q.'%');
$stmt->bindValue(':e',$e);
$stmt->execute();
$startPage = ($pageno <5) ? 1 : $pageno -4;
$endPage = 8 + $startPage;
$endPage = ($maxpage < $endPage) ? $maxpage : $endPage;
$diff = $startPage - $endPage + 8;
$startPage -=($startPage - $diff > 0) ? $diff : 0;
$a = $startPage;
echo "<ol id='olpoint'>";
if($startPage > 1) echo "<a href='#' onclick='ajaxSearchUpdater(1);'><li>First</li></a>";
while($a<=$endPage){
echo "<a href='#' onclick='ajaxSearchUpdater(".$a.");' style='text-decoration:none;'><li ";
if($pageno == $a){
echo "style='color:grey;font-size:medium;'";
}
echo ">".$a."</li></a>";
$a++;
};
if($endPage < $maxpage) echo "<a href='#' onclick='ajaxSearchUpdater(".$maxpage.");'><li>End</li></a>";
echo "</ol>";
if($stmt->rowCount() > 0){
$r=$stmt->fetchAll();
echo "<table class='tablesorter-blackice' id='myTable' style='width:97%; table-border: 1'>";
echo "<thead>";
echo "<tr>";
echo "<th>No.</th>";
echo "<th>No.Matric</th>";
echo "<th>Name</th>";
echo "<th>Programme</th>";
echo "<th>Title</th>";
echo "<th>Thesis Level</th>";
echo "<th>Serial Number</th>";
echo "<th>Availability</th>";
echo "<th>Select book (Max 3)</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
if(isset($_SESSION['sBorrow']))
$arraynosiri = $_SESSION['sBorrow'];
else
$arraynosiri = array();
$countses = count($_SESSION['sBorrow']);
foreach($r as $row){
echo "<tr align='center'><td>". ($startrow+1) ."</td><td>". $row['matricno'] ."</td><td>". $row['studentname'] ."</td><td>". $row['programme'] ."</td><td>". $row['title'] ."</td><td>". $row['thesis_level'] ."</td><td>". $row['serialno'] ."</td><td>". $row['bavailable'] ."</td><td>
<form id='checkbook' name='checkbook' method='post'>";
if($key = array_search($row['serialno'], $arraynosiri) !== false) {
$checkbox = "checked";
}
else{
$checkbox = "";
}
/*
if($countses === 3){
echo "<script>
var checkboxes = $('.sBorrow').not(':checked');
$.each(checkboxes, function(idx, cb) {
$(cb).attr('disabled', 'disabled');
});
</script>";
}
else{
echo "<script>
$(cb).attr('disabled', false)
</script>";
}*/
if($row['bavailable'] == "Available"){
echo "<input type='checkbox' name='sBorrow' class='sBorrow' value='". $row['serialno'] ."' ".$checkbox.">
</form></td></tr>";
}
else{
echo "<input type='checkbox' name='sBorrow' class='sBorrow' value='". $row['serialno'] ."' ".$checkbox." style='color: grey;' disabled>
</form></td></tr>";
}
$startrow++;
//echo $row['education_level'];
}
echo "</tbody>";
echo "</table>";
}
else{
echo "<p align='center' style='color:white'; class='reminder'>Nothing to show you :( I am really sorry for this T_T </p>";
}
?>
I just wondering how to save the session of the checkbox limitations rule so that, it still count on the other page. Truthfully, im seriously stuck.
Aucun commentaire:
Enregistrer un commentaire