|
|
|
แบ่งหน้าไม่ถูกต้องครับ หน้าแรกและหน้าสุดท้ายปกติ แต่หน้า 2 3 ... จะ *2 จากจำนวนต่อหน้าที่กำหนด |
|
|
|
|
|
|
|
แบ่งหน้าไม่ถูกต้องครับ หน้าแรกและหน้าสุดท้ายปกติ แต่หน้า 2 3 ... จะ *2 จากจำนวนต่อหน้าที่กำหนด
Code (PHP)
<?php
$nb = $db->prepare('SELECT *
FROM tbl_machine
WHERE list LIKE :keyword
ORDER BY machine_id ASC');
$nb->bindParam(':keyword',$keyword, PDO::PARAM_STR);
$nb->execute();
$num_rows = $nb->rowCount();
$per_page = 15; // Per Page
$page = 1;
if(isset($_GET["Page"])){
$page = $_GET["Page"];
}
$prev_page = $page-1;
$next_page = $page+1;
$row_start = (($per_page*$page)-$per_page);
if($num_rows<=$per_page){
$num_pages =1;
}
else if(($num_rows % $per_page)==0){
$num_pages =($num_rows/$per_page) ;
}
else{
$num_pages =($num_rows/$per_page)+1;
$num_pages = (int)$num_pages;
}
$row_end = $per_page * $page;
if($row_end > $num_rows){
$row_end = $num_rows;
}
$nb = $db->prepare('SELECT tbl_machine.list,tbl_machine.code,tbl_machine.type,tbl_machine.status,tbl_machine.machine_id,tbl_type.type
FROM tbl_machine
INNER JOIN tbl_type ON tbl_machine.type=tbl_type.id
WHERE list LIKE :keyword
ORDER BY machine_id ASC
LIMIT :row_start ,:row_end');
$nb->bindParam(':keyword',$keyword, PDO::PARAM_STR);
$nb->bindParam(':row_start', $row_start, PDO::PARAM_STR);
$nb->bindParam(':row_end', $row_end, PDO::PARAM_STR);
$nb->execute();
?>
<table class="table table-striped table-bordered" id="manage">
<thead>
<!-- <th style="text-align: center;">
<input type="checkbox" value="" name="chkAll" id="chkAll">
</th> -->
<th style="text-align: center;">#</th>
<th style="text-align: center;" class="headerSortUp">ชื่อเครื่อง</th>
<th style="text-align: center;" class="headerSortUp">รหัสครุภัณฑ์</th>
<th style="text-align: center;" class="headerSortUp">หมวดหมู่</th>
<th style="text-align: center;" class="headerSortUp">สถานะเครื่อง</th>
<th style="text-align: center;">จัดการ</th>
</thead>
<?php
$i=1;
if($page > 1){
$i = ($per_page * ($page-1)) + 1;
}
while ($row = $nb->fetch(PDO::FETCH_ASSOC)) {
if ($row['status'] == 'idle') {
$status = 'ว่าง';
}
elseif ($row['status'] == 'busy') {
$status = 'ถูกใช้งาน';
}
else {
$status = 'ซ่อม';
}
?>
<tbody>
<tr>
<!--<td style="text-align: center;">
<input type="checkbox" name="chkDelete[]" id="chkDelete" value="<?=$row['machine_id'];?>" >
<!--</div>
</td>-->
<td style="text-align: center;"><?php echo $i; ?></td>
<td style="text-align: center;"><?php echo $row['list']; ?></td>
<td style="text-align: center;"><?php echo $row['code']; ?></td>
<td style="text-align: center;"><?php echo $row['type']; ?></td>
<td style="text-align: center;"><?php echo $status; ?></td>
<td style="text-align: center;">
<a name="btnView" id="btnView" type="button" class="btn btn-info btn-xs" href="view-parcel?id=<?=$row['machine_id'];?>"><span class="glyphicon glyphicon-eye-open" aria-hidden="true"></span> ดู</a>
<a name="btnUpdate" id="btnUpdate" type="button" class="btn btn-warning btn-xs" href="update-parcel?id=<?=$row['machine_id'];?>"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> แก้ไข</a>
<a name="btnDanger" id="btnDanger" type="button" class="btn btn-danger btn-xs" data-toggle="modal" data-target="#confirm-delete" data-href="<?php echo $_SERVER["PHP_SELF"];?>?Action=Delete&del=<?php echo $row["machine_id"];?>" ><span class="glyphicon glyphicon-remove" aria-hidden="true"></span> ลบ</a>
</td>
</tr>
<?php
$i++;
} //end while
?>
</tbody>
</table>
<br>
ทั้งหมด <?php echo $num_rows;?> รายการ
<nav aria-label="Page navigation">
<ul class="pagination pull-right" style="margin-top:0;">
<?php
if($prev_page){
echo " <li><a href ='$_SERVER[SCRIPT_NAME]?Page=$prev_page&txtKeyword=$strKeyword'><span aria-hidden='true'>Back «</span></a></li> ";
}
for($i=1; $i<=$num_pages; $i++){
if($i != $page){
echo "<li> <a href='$_SERVER[SCRIPT_NAME]?Page=$i&txtKeyword=$strKeyword'>$i</a> </li>";
}
else{
echo "<li class='active'><a href='#'> $i <span class='sr-only'>(current)</span></a></li>";
}
}
if($page!=$num_pages){
echo " <li><a href ='$_SERVER[SCRIPT_NAME]?Page=$next_page&txtKeyword=$strKeyword'><span aria-hidden='true'>Next »</span></a></li> ";
}
?>
</ul>
</nav>
<div class="col-lg-1 pull-right">
<select name="ddlPage" class="form-control" onchange="javascript:window.location='?Page='+this.options[this.selectedIndex].value+'&txtKeyword=<?php echo $strKeyword;?>';">
<?php
for($x=1; $x<=$num_pages; $x++){
?>
<option value="<?php echo $x;?>" <?php if($page==$x){echo "selected";}?>> <?php echo $x;?> </option>
<?php
}
?>
</select>
</div>
Tag : PHP, MySQL, HTML/CSS, JavaScript, Ajax, jQuery
|
ประวัติการแก้ไข 2016-11-01 13:46:32
|
|
|
|
|
Date :
2016-11-01 13:32:45 |
By :
littlebeer |
View :
746 |
Reply :
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ถ้าไม่ว่าอะไรก็ใช้ class Pagination ที่ผมแจก
|
|
|
|
|
Date :
2016-11-01 14:01:44 |
By :
mr.v |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2016-11-01 14:29:31 |
By :
apisitp |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ได้ละครับ
|
|
|
|
|
Date :
2016-11-01 15:34:26 |
By :
littlebeer |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2016-11-02 09:28:37 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|