��ҹ��Ǣ�͡�͹˹�� :: ��ҹ��Ǣ�ͶѴ� |
����� |
��ͤ��� |
ryuozero Site Admin
�������: 13 Jul 2005 �ͺ: 1145
|
�ͺ�����: Fri Sep 11, 2009 3:30 am ����ͧ: PHP ��˹���ʴ��Ţ����� |
|
|
��ҧ�ԧ�ҡ: |
<head>Code �ش��� 1</head>
<code>
$strSQL = "select * from account where username like '%".$_REQUEST['search']."%' order by username";
}
//Function WS page >>>>>>>>>>>>>
$Per_Page = 20;
if ( !$Page )
$Page = 1;
$Prev_Page = $Page - 1;
$Next_Page = $Page + 1;
$result = mysql_query( $strSQL );
$Page_start = ( $Per_Page * $Page ) - $Per_Page;
$Num_Rows = mysql_num_rows( $result );
if ( $Num_Rows <= $Per_Page )
$Num_Pages = 1;
elseif ( ( $Num_Rows % $Per_Page ) == 0 )
$Num_Pages = ( $Num_Rows / $Per_Page );
else
$Num_Pages = ( $Num_Rows / $Per_Page ) + 1;
$Num_Pages = ( int ) $Num_Pages;
if ( ( $Page > $Num_Pages ) || ( $Page < 0 ) )
print "�ӹǹ $Page �ҡ���� $Num_Pages";
$strSQL .= " LIMIT $Page_start, $Per_Page";
$result = mysql_query( $strSQL );
$totals = mysql_num_rows($result);
</code>
<head>Code �ش�ʴ���</head>
<code>
<?php
/* ���ҧ������͹��Ѻ */
if ( $Prev_Page )
echo "<a href=\"index2.php?option=user_history&submit&start=".$_REQUEST['start']."&end=".$_REQUEST['end']."&Page=$Prev_Page\">< Prev </a>";
/* ���ҧ����Ţ˹�� */
for ( $i=1; $i<=$Num_Pages; $i++ )
{
if ( $i != $Page ) echo "<a href=\"index2.php?option=user_history&submit&start=".$_REQUEST['start']."&end=".$_REQUEST['end']."&Page=$i\">$i </a>";
else echo " <b>[$i]</b> ";
}
/* ���ҧ�����Թ˹�� */
if ( $Page != $Num_Pages )
echo "<a href=\"index2.php?option=user_history&submit&start=".$_REQUEST['start']."&end=".$_REQUEST['end']."&Page=$Next_Page\"> Next ></a>";
?>
</code>
######## ���Ѿ���� ����ҳ����Ѻ <Prev Page: 1 [2] 3 Next >
�����ҡ�Тͤ�����������ͤ���ҡ�ա���ʴ����͡�������繾ѹ�ѹ��������ҡ ��ҡ����ѹ������ҳ���
���Ẻ��� < first 1 2 [3] 4 .... 10 Last > ����ҳ����Ф�Ѻ
** ���� code �ç�˹������ ú�ǹ����д��¤�Ѻ |
|
|
���仢�ҧ�� |
|
|
ryuozero Site Admin
�������: 13 Jul 2005 �ͺ: 1145
|
�ͺ�����: Fri Sep 11, 2009 3:31 am ����ͧ: |
|
|
Code: |
$strSQL = "select * from account where username like '%".$_REQUEST['search']."%' order by username";
}
//Function WS page >>>>>>>>>>>>>
$Per_Page = 20;
if ( !$Page )
$Page = 1;
$Prev_Page = $Page - 1;
$Next_Page = $Page + 1;
$result = mysql_query( $strSQL );
$Page_start = ( $Per_Page * $Page ) - $Per_Page;
$Num_Rows = mysql_num_rows( $result );
if ( $Num_Rows <= $Per_Page )
$Num_Pages = 1;
elseif ( ( $Num_Rows % $Per_Page ) == 0 )
$Num_Pages = ( $Num_Rows / $Per_Page );
else
$Num_Pages = ( $Num_Rows / $Per_Page ) + 1;
$Num_Pages = ( int ) $Num_Pages;
if ( ( $Page > $Num_Pages ) || ( $Page < 0 ) )
print "�ӹǹ $Page �ҡ���� $Num_Pages";
$strSQL .= " LIMIT $Page_start, $Per_Page";
$result = mysql_query( $strSQL );
$totals = mysql_num_rows($result); |
Code �ش�ʴ���
Code: |
<?php
/* ���ҧ������͹��Ѻ */
if ( $Prev_Page )
echo "<a href=\"index2.php?option=user_history&submit&start=".$_REQUEST['start']."&end=".$_REQUEST['end']."&Page=$Prev_Page\">< Prev </a>";
/* ���ҧ����Ţ˹�� */
for ( $i=1; $i<=$Num_Pages; $i++ )
{
if ( $i != $Page ) echo "<a href=\"index2.php?option=user_history&submit&start=".$_REQUEST['start']."&end=".$_REQUEST['end']."&Page=$i\">$i </a>";
else echo " <b>[$i]</b> ";
}
/* ���ҧ�����Թ˹�� */
if ( $Page != $Num_Pages )
echo "<a href=\"index2.php?option=user_history&submit&start=".$_REQUEST['start']."&end=".$_REQUEST['end']."&Page=$Next_Page\"> Next ></a>";
?> |
######## ���Ѿ���� ����ҳ����Ѻ <Prev Page: 1 [2] 3 Next >
�����ҡ�Тͤ�����������ͤ���ҡ�ա���ʴ����͡�������繾ѹ�ѹ��������ҡ ��ҡ����ѹ������ҳ���
���Ẻ��� < first 1 2 [3] 4 .... 10 Last > ����ҳ����Ф�Ѻ
** ���� code �ç�˹������ ú�ǹ����д��¤�Ѻ �����¤�Ѻ���������ͧ comment �Դ�֧����٧���� |
|
���仢�ҧ�� |
|
|
ryuozero Site Admin
�������: 13 Jul 2005 �ͺ: 1145
|
�ͺ�����: Fri Sep 11, 2009 3:32 am ����ͧ: |
|
|
�աẺ
��ҧ�ԧ�ҡ: |
�����˹���ʴ��Ţ����Ŵ�����֡���..���繻Ñ������Ѻ�������¹ Web Application ������������� ���ͧ�ҡ���.. ��ͧ������ǤԴ ��С�äӹǹ������������·����� ���ͧ㹡��������֡��¹���� � ��������������ѹ����͹�ѹ�Ѻ����ͧ�ç��� 㹺��������֧�����������ҹ�ͧ�֡�ҡѹ�٤�Ѻ
��õѴ˹�Ң������ʴ���
<?php
$link=mysql_connect("localhost","username","password");
mysql_select_db("database name",$link);
$sql="Select count(*) From stu_name"; //�Ѻ�ӹǹ Record ������� Table
$rs=mysql_query($sql);
$total_rec=mysql_result($rs,0,0); // �纨ӹǹ Record ���������� $total_page
$p_size=25; //��˹��ӹǹ Record �����ʴ��ŵ�� 1 ྨ
$total_page=(int)($total_rec/$p_size);
//�ӡ������Ҩӹǹ˹�ҷ������ͧ������ 㹷�����������͡�����Ţ�ӹǹ���
if(($total_rec % $p_size)!=0){ //��Ң�������������ӡ�úǡ�����ӹǹ˹���ա 1
$total_page++;
}
if(empty($_GET['page'])){
/*
�����ѧ����ա���觤�������ͷӡ�����͡��˹�Ң������ � ����˹���˹���á�ͧ�������繤�� Default ������ Record �á�������� Record ��� 0 ���� Record �á
*/
$page=1;
$start=0;
}else{
/*
�ҡ�ա���觤�����������͡��˹�Ң�����˹������ӡ�äӹǹ ���� �ӹǹ�����ŷ���ͧ����ʴ���� 1 ྨ �ٳ�Ѻ ˹�Ң����ŷ���ͧ������͡�� ź���� 1
*/
$page=$_GET['page'];
$start=$p_size*($page-1);
}
$sql="Select * From stu_name LIMIT $start , $p_size";
//�� Option LIMIT �ͧ MySQL ���ͷӡ�����͡�������͡�ҵ����ͧ���
$rs=mysql_query($sql);
while($result=mysql_fetch_array($rs)){ //ǹ�ͺ�ʴ�������
echo $result["Name"]."<br>";
}
for($i=1;$i<=$total_page;$i++){ //���ҧ Link �����������ҹ���͡��˹�Ң�����
echo "<a href=".$_SERVER['PHP_SELF']."?page=".$i.">˹�ҷ�� ".$i."</a> ";
}
?> |
|
|
���仢�ҧ�� |
|
|
|