|
|
|
สอบถามปัญหา PHP MySQL List Record Paging/Pagination |
|
|
|
|
|
|
|
กดไปหน้า2 แต่ข้อมูลมันขึ้น เพราะอะไรครับ
Code (PHP)
<?
include "session.php";
?>
<!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=windows-874" />
<script language="javascript" src="../include/time.js">
</script>
<title>ระบบหนังสือเวียน</title>
<link rel="stylesheet" type="text/css" href="menu_admin.css">
<style type="text/css">
<!--
A:link {COLOR: #000000; TEXT-DECORATION: none}
A:visited {COLOR: #000000; TEXT-DECORATION: none}
A:hover {COLOR: #FF0000; TEXT-DECORATION: underline}
.style4 {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
color: #FFFFFF;
}
.style9 {color: #FF0000}
.style15 {font-size: 13px; color: #22222; }
.style24 {
color: #0000FF;
font-size: 14px;
}
-->
</style>
</head>
<body bgcolor="#999999" leftmargin="0" topmargin="0" >
<table width="800" height="729" border="0" cellspacing="0" align="center" CELLPADDING=0 > <!-- start table 1 -->
<tr>
<td width="786" height="196" background="../images/head_02.jpg"></td>
</tr>
<tr>
<td width="786" height="20" > <? include "menu_admin.php"?></td>
<tr>
<td width="786" height="413" align="center">
<table width="800" height="412" border="0" cellpadding="0" cellspacing="0"><!-- start table 2 -->
<tr>
<th width="10" bgcolor="#ccffff" scope="col"> </th>
<th width="175" align="center" valign="top" bgcolor="#ccffff" scope="col">
<table width="175" border="0">
<tr align="left">
<td height="28" colspan="2"> </td>
</tr>
<tr align="left">
<td height="35" colspan="2"><span class="style24">Main Menu</span><br>
<hr></td>
</tr>
<tr>
<td height="25" align="right"><img src="../images/5_06.GIF" /></td>
<td align="left"><a href="add_position.php">เพิ่มตำแหน่ง</a></td>
</tr>
<tr>
<td height="24" align="right"><img src="../images/5_06.GIF" /></td>
<td align="left"> <a href="view_position.php">แสดง/ลบ/แก้ไข ตำแหน่ง</a></td>
</tr>
<tr>
<td height="26" align="right"><img src="../images/5_06.GIF" /></td>
<td align="left"> <a href="search_position.php">ค้นหาตำแหน่ง</a></td>
</tr>
<tr>
<td height="43" align="right"> </td>
<td align="left"> </td>
</tr>
<tr>
<td height="42" colspan="2" align="left" valign="top"><span class="style24">Hello Admin</span><br>
<hr></td>
</tr>
<tr>
<td height="43" colspan="2" align="center"> <span class="style22"> Admin </span></td>
<tr>
<td height="43" colspan="2" align="center"><img src="../images/admin.png" width="100" height="100" /></td>
<tr>
<td height="43" colspan="2" align="center"><a href="../logout.php" class="style23 style9"><font color="#FF0000" >ออกจากระบบ </font></a></td>
</tr>
</table> <br>
<br /><br /></th>
<th width="10" bgcolor="#00ffff" scope="col"> </th>
<td width="605" align="center" valign="top" bgcolor="#ccffff" scope="col">
<br > <br >
<table width="435" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#B4B4B4" style="border-collapse: collapse" ><!-- start table 3 -->
<tr align="center" bgcolor="#00ffff">
<th width="160" height="48" scope="row"><span class="style15">ชื่อตำแหน่งพนักงาน</span></th>
<th width="191" bgcolor="#00ffff"><span class="style15">รายละเอียด</span></th>
<th width="76"><span class="style15">แก้ไข/ลบ</span></th>
</tr>
<?
(!isset($_REQUEST[”page”])) ? $page = 1 : $page=$_REQUEST[”page”];
include "../include/connect.php";
$sql="select * from position";
$result =mysqli_query($conn,"set names tis620");
$result=mysqli_query($conn,$sql);
$totalrecord = mysqli_num_rows($result);
$pagesize = 15;
$totalpage = (int) ($totalrecord / $pagesize);
if (($totalrecord % $pagesize) != 0) {
$totalpage += 1;
}
if (isset($pageid)) {
$start = $pagesize * ($pageid - 1);
}
else {
$pageid = 1;
$start = 0;
}
$sql = "SELECT * FROM position order by position_id LIMIT $start, $pagesize;";
$result = mysqli_query($conn,$sql);
$i = 0;
while($data=mysqli_fetch_array($result))
{
if($i%2 == 0){
?>
<tr align="left" bgcolor="#66FFFF">
<?
}else{
?>
<tr align="left" bgcolor="#D7FBFB">
<?
}
?>
<td width=160 height="33" > <?=$data[position_name] ?></a>
<td > <?= $data[position_detail] ?>
<th align="center"> <A HREF="edit_position.php?position_id=<?=$data[position_id]?>"><img src="../images/edit.gif" border="0"/></A> <A HREF="delete_position_main.php?position_id=<?=$data[position_id]?>" onclick=" return confirm
('ยืนยันลบข้อมูล <?=$data[position_name]?> ออกจากระบบ' ) " ><img src="../images/del.gif" border="0" /></A></tr >
<?
$i++;
}
?>
</table><!-- END table 3 -->
<?
echo "<br >หน้าที่ ";
for ($i=1; $i<=$totalpage; $i++) {
if ($i == $pageid) {
echo $i . " ";
}
else {
echo "[<a href=\"view_position.php?pageid=$i\">$i</a>] ";
}
}
?>
<br ><br > <br ><br >
</td>
</tr>
</table><!-- END table 2 --> </tr>
<tr>
<td width="786" height="100" background="../images/head_05.jpg" >
<div align="right">
<p> </p>
<p align="center"><span class="style4">
<? include "footer.php"?></p>
</div> </td>
</tr>
</table>
<!-- END table 3 -->
</body>
</html>
Tag : PHP, MySQL, HTML/CSS, JavaScript, Ajax, jQuery
|
|
|
|
|
|
Date :
2016-05-24 11:45:59 |
By :
settachai |
View :
710 |
Reply :
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
กดไปแล้ว หน้า2แล้ว ข้อมูล หน้า1 ยังอยู่เหมือนเดิม
|
|
|
|
|
Date :
2016-05-24 11:46:48 |
By :
settachai |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$pageid ไม่มีค่าครับลองตรวจสอบดู
ตรงนี้หน้าจะเป็นแบบนี้หรือเปล่า
Code (PHP)
(!isset($_REQUEST[”pageid”])) ? $pageid= 1 : $pageid=$_REQUEST[”pageid”];
|
|
|
|
|
Date :
2016-05-24 12:11:55 |
By :
aimoomoo |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
echo $sql; ออกมาดูแล้วดูว่าตรงหลัง LIMIT หน้าแรกเป็นไง หน้าสองเป็นไง มันติดอยู่ตรงนี้แหละครับ
|
|
|
|
|
Date :
2016-05-24 13:48:03 |
By :
mr.v |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|