|
 |
|
ปัญหา การสร้าง nextpage คือ ผมมี record อยู่ แต่หน้าที่ 2 เหมือนกับ หน้า 1 |
|
 |
|
|
 |
 |
|
คือ ผมมี record อยู่ 13 แบ่งเป็น หน้าละ 10 แต่พอกดดู หน้า 1 มันมี 13 เหมือนกับ หน้า 2

นี้ โค้ด ครับ
Code (PHP)
<?php
$sql = "select * from tbl_users where 1=1";
if($_POST["Search"]){
if($username != ""){
$sql.=" and username like '%$username%'";
}
if($empcode != ""){
$sql.=" and emp_code like '%$emp_code%'";
if($condition == "1"){
$sqlData = "select user_id, username, password, emp_code from tbl_users where user_level = 1 ";
$queryData = mysql_query($sqlData);
$rowData = mysql_fetch_array($queryData);
//print_r($rowData);
}
if($condition == "2"){
$sqlData = "select user_id, username, password, emp_code from tbl_users where user_level = 2 ";
$queryData = mysql_query($sqlData);
$rowData = mysql_fetch_array($queryData);
//print_r($rowData);
}if($condition == "3"){
$sqlData = "select user_id, username, password, emp_code from tbl_users where user_level = 3 ";
$queryData = mysql_query($sqlData);
$rowData = mysql_fetch_array($queryData);
//print_r($rowData);
}
}
}
$query = mysql_query($sql);
$nums = mysql_num_rows($query);
$Per_Page = 10; // Per Page
$Page = $_GET["Page"];
if(!$_GET["Page"])
{$Page=1;
}
$Prev_Page = $Page-1;
$Next_Page = $Page+1;
$Page_Start = (($Per_Page*$Page)-$Per_Page);
if($nums<=$Per_Page){
$Num_Pages =1;
}
else if(($nums % $Per_Page)==0){
$Num_Pages =($nums/$Per_Page) ;
}
else{
$Num_Pages =($nums/$Per_Page)+1;
$Num_Pages = (int)$Num_Pages;
}
$strSQL .=" order by CustomerID ASC LIMIT $Page_Start , $Per_Page";
$objQuery = mysql_query($strSQL);
//echo "<br>";
//echo $sql;
$i=1;
while($rows = mysql_fetch_array($query)){
?>
<tr>
<td bordercolor="#000000"><div align="center"><?php echo $i;?></div></td>
<td bordercolor="#000000"><div align="center"><?php echo $rows["username"];?></div></td>
<td bordercolor="#000000"><div align="center"><?php echo $rows["password"];?></div></td>
<td bordercolor="#000000">
<div align="center"><?php
if( $rows["user_level"] == "1"){
echo "ผู้ดูแลระบบ";
}if( $rows["user_level"] == "2"){
echo "เจ้าหน้าที่บันทึกข้อมูล";
}if( $rows["user_level"] == "3"){
echo "ผู้ใช้งานทั่วไป";
}
?></div></td>
<td bordercolor="#000000"><div align="center"><?php echo $rows["emp_code"];?></div></td>
<td bordercolor="#000000"><div align="center"><a href="edit_user.php?user_id=<?php echo $rows["user_id"];?>">คลิก</a></div></td>
<td align="center" bordercolor="#000000"><div align="center"><a href="JavaScript:if(confirm('คุณต้องการลบข้อมูลผู้ใช้รายนี้ ใช่ หรือ ไม่ ?')==true){window.location='Deleteuser.php?delete_id=<?php echo $rows["user_id"];?>';}">คลิก</a></div></td>
</tr>
<?php
$i++;}
?>
<?php
if($nums == 0){
?>
<tr>
<td colspan="7" bordercolor="#000000"><div align="center" class="style13 style2">ไม่พบรายการที่ค้นหา</div></td>
</tr>
<?php
}
?>
</table>
</form>
<script type="text/javascript">
function show_confirm()
{
var r = confirm("!! คุณต้องการออกจากระบบ ใช่ หรือ ไม่ !!");
if (r==true)
{
location="logout.php";
}else{
location="select_user.php";
}
}
</script>
<br>
Total <?= $nums;?> Record : <?=$Num_Pages;?> Page :
<?
if($Prev_Page)
{
echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page'><< Back</a> ";
}
for($i=1; $i<=$Num_Pages; $i++){
if($i != $Page)
{
echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i'>$i</a> ]";
}
else
{
echo "<b> $i </b>";
}
}
if($Page!=$Num_Pages)
{
echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page'>Next>></a> ";
}
?>
ขอบคุณล่วงหน้า ครับ
Tag : PHP

|
|
 |
 |
 |
 |
Date :
2011-04-20 14:48:51 |
By :
paksabkk |
View :
1437 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

พอเป็น แก้ไข แล้ว มันกลับ ไม่ ขึ้น record ใดๆ เลย ครับ เหมื่อนกับว่า ไม่มีข้อมูลอยู่
ที่มันขึ้น error line 135 ที่ จริงแล้ว เป็น
line 085. $i++;}
ในกระทู้ นะครับ เพราะ ผม copy code มาบางส่วน
|
ประวัติการแก้ไข 2011-04-22 08:45:25 2011-04-22 09:01:28
 |
 |
 |
 |
Date :
2011-04-22 08:43:38 |
By :
paksabkk |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ครับ เดี๋ยว ผม จะ ลอง แกะๆ ดู ขอบคุณครับ
|
 |
 |
 |
 |
Date :
2011-04-22 12:50:55 |
By :
paksabkk |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|