|
|
|
ใช้คำสั่ง <?php echo ++$n ?> แล้วพอกดไปpage 2 มันยังเรียงจาก1 เหมือเดิม ถ้าต้องการเรียงค่าจากหน้าแรกต้องทำไงครับ |
|
|
|
|
|
|
|
อธิบายให้ชัดเจน พร้อมโค๊ดก็ดีครับ
|
|
|
|
|
Date :
2013-02-11 21:27:08 |
By :
Ex-[S]i[L]e[N]t |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
กระทู้แบ่งหน้า เพจเก่าๆมีเยอะ จับสัก Code ไปประยุกต์เด๋วก็ได้
|
|
|
|
|
Date :
2013-02-11 21:58:38 |
By :
apisitp |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<table width="99%" height="268" border="0">
<tr>
<td height="69" bgcolor="#FFFFFF">
<form name="frmSearch" method="get" action="<?=$_SERVER['SCRIPT_NAME'];?>">
<p> </p>
<table width="599" border="0">
<tr>
<th>ค้นหานักเรียน
<input name="txtKeyword" type="text" id="txtKeyword" value="<?=$_GET["txtKeyword"];?>">
<input type="submit" value="Search"></th>
</tr>
</table>
</form><?
$level_class=$_GET['level_class'];
$sql = "Select * From saveactivity WHERE (fname_std LIKE '%".$_GET["txtKeyword"]."%' or lname_std LIKE '%".$_GET["txtKeyword"]."%' or year_edu LIKE '%".$_GET["txtKeyword"]."%' ) group by id_std,term,year_edu";
$sqlq = mysql_query($sql) or die ("Error Query [".$sql."]");
$Num_Rows = mysql_num_rows($sqlq);
$Per_Page = 20; // 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($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;
}
$sql .=" order by id_saveactivity ASC LIMIT $Page_Start , $Per_Page";
$sqlq = mysql_query($sql);
?>
</td>
</tr>
<tr>
<td height="75" align="center" valign="top">
<table width="530" height="72" border="1" bordercolor="#9DECA2" cellpadding="0" cellspacing="0">
<tr>
<td width="18%" height="38" align="center" bgcolor="#9DECA2">รหัสการบันทึก</td>
<td width="16%" align="center" bgcolor="#9DECA2">รหัสนักเรียน</td>
<td width="26%" align="center" bgcolor="#9DECA2">ชื่อ - สกุล</td>
<td width="15%" align="center" bgcolor="#9DECA2">ปีการศึกษา</td>
<td width="7%" align="center" bgcolor="#9DECA2">เทอม</td>
<td width="18%" align="center" bgcolor="#9DECA2">ประวัติ</td>
</tr>
<? $i = 1;
if($Page > 1)
{
$i = ($Per_Page * ($Page-1)) + 1;
}
while($row=mysql_fetch_array($sqlq)){
$autoid = $row['id_saveactivity'];
?>
<tr>
<tr bgcolor="<? echo $bg?>" onMouseOver="this.style.backgroundColor='#CCFFCC'" onMouseOut="this.style.backgroundColor=''" valign="top">
<td height="30"><?=++$n; ?></td>
<td> <?=$row['id_std'];?></td>
<td> <? echo $row['fname_std'];?> <? echo $row['lname_std'];?></td>
<td><? echo $row['year_edu'];?></td>
<td><? echo $row['term'];?></td>
<td><a href="print_saveactivity.php?id_saveactivity=<?=$row['id_saveactivity'];?>&id_std=<?=$row['id_std'];?>&term=<?=$row['term'];?>&year_edu=<?=$row['year_edu'];?>">พิมพ์รายงาน</a></td>
</tr>
<? } ?>
</table></td>
</tr>
<tr>
<td align="right" valign="top" bgcolor="#FFFFFF"> Total <?= $Num_Rows;?> 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> ";
}
?> </td>
</tr>
</table>
<table width="99%" height="268" border="0">
<tr>
<td height="69" bgcolor="#FFFFFF">
<form name="frmSearch" method="get" action="<?=$_SERVER['SCRIPT_NAME'];?>">
<p> </p>
<table width="599" border="0">
<tr>
<th>ค้นหานักเรียน
<input name="txtKeyword" type="text" id="txtKeyword" value="<?=$_GET["txtKeyword"];?>">
<input type="submit" value="Search"></th>
</tr>
</table>
</form><?
$level_class=$_GET['level_class'];
$sql = "Select * From saveactivity WHERE (fname_std LIKE '%".$_GET["txtKeyword"]."%' or lname_std LIKE '%".$_GET["txtKeyword"]."%' or year_edu LIKE '%".$_GET["txtKeyword"]."%' ) group by id_std,term,year_edu";
$sqlq = mysql_query($sql) or die ("Error Query [".$sql."]");
$Num_Rows = mysql_num_rows($sqlq);
$Per_Page = 20; // 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($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;
}
$sql .=" order by id_saveactivity ASC LIMIT $Page_Start , $Per_Page";
$sqlq = mysql_query($sql);
?>
</td>
</tr>
<tr>
<td height="75" align="center" valign="top">
<table width="530" height="72" border="1" bordercolor="#9DECA2" cellpadding="0" cellspacing="0">
<tr>
<td width="18%" height="38" align="center" bgcolor="#9DECA2">รหัสการบันทึก</td>
<td width="16%" align="center" bgcolor="#9DECA2">รหัสนักเรียน</td>
<td width="26%" align="center" bgcolor="#9DECA2">ชื่อ - สกุล</td>
<td width="15%" align="center" bgcolor="#9DECA2">ปีการศึกษา</td>
<td width="7%" align="center" bgcolor="#9DECA2">เทอม</td>
<td width="18%" align="center" bgcolor="#9DECA2">ประวัติ</td>
</tr>
<? $i = 1;
if($Page > 1)
{
$i = ($Per_Page * ($Page-1)) + 1;
}
while($row=mysql_fetch_array($sqlq)){
$autoid = $row['id_saveactivity'];
?>
<tr>
<tr bgcolor="<? echo $bg?>" onMouseOver="this.style.backgroundColor='#CCFFCC'" onMouseOut="this.style.backgroundColor=''" valign="top">
<td height="30"><?=++$n; ?></td>
<td> <?=$row['id_std'];?></td>
<td> <? echo $row['fname_std'];?> <? echo $row['lname_std'];?></td>
<td><? echo $row['year_edu'];?></td>
<td><? echo $row['term'];?></td>
<td><a href="print_saveactivity.php?id_saveactivity=<?=$row['id_saveactivity'];?>&id_std=<?=$row['id_std'];?>&term=<?=$row['term'];?>&year_edu=<?=$row['year_edu'];?>">พิมพ์รายงาน</a></td>
</tr>
<? } ?>
</table></td>
</tr>
<tr>
<td align="right" valign="top" bgcolor="#FFFFFF"> Total <?= $Num_Rows;?> 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> ";
}
?> </td>
</tr>
</table>
|
|
|
|
|
Date :
2013-02-11 22:06:21 |
By :
kiratas |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|