|
|
|
จะโชว์นะหน้า 20 เร็คคอร์ด ทำไงอะ $sql_select="select * from worksystem";สมมติคิวรี่มาได้ 200 เร็คคอร์ด |
|
|
|
|
|
|
|
https://www.thaicreate.com/php/php-mysql-list-record-paging.html
|
|
|
|
|
Date :
2009-09-14 15:52:05 |
By :
deawx |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
$strSQL = "SELECT * FROM customer ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$Num_Rows = mysql_num_rows($objQuery);
$Per_Page = 2; // 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;
}
$strSQL .=" order by CustomerID ASC LIMIT $Page_Start , $Per_Page";
$objQuery = mysql_query($strSQL);
?>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">CustomerID </div></th>
<th width="98"> <div align="center">Name </div></th>
<th width="198"> <div align="center">Email </div></th>
<th width="97"> <div align="center">CountryCode </div></th>
<th width="59"> <div align="center">Budget </div></th>
<th width="71"> <div align="center">Used </div></th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<tr>
<td><div align="center"><?=$objResult["CustomerID"];?></div></td>
<td><?=$objResult["Name"];?></td>
<td><?=$objResult["Email"];?></td>
<td><div align="center"><?=$objResult["CountryCode"];?></div></td>
<td align="right"><?=$objResult["Budget"];?></td>
<td align="right"><?=$objResult["Used"];?></td>
</tr>
<?
}
?>
</table>
<br>
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> ";
}
mysql_close($objConnect);
?>
</body>
</html>
|
|
|
|
|
Date :
2009-09-14 15:53:07 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
$txtfname=$_POST[txtfname];
$txtlname=$_POST[txtlname];
$pageid=$_GET[pageid];
if($txtfname!=''){
$sql_select="select * from uoc_std WHERE ((STD_FNAME LIKE '$txtfname%') AND (STD_LNAME LIKE '$txtlname%'))";
$result= mysql_query( $sql_select, $conn );
$totalRows= mysql_num_rows($result);
$pagesize=20;
$totalpage=(int) ($totalRows / $pagesize);
if(($totalRows % $pagesize) !=0) {
$totalpage +=1;
}
if(isset($pageid)){
$start=$pagesize * ($pageid-1);
}
else {
$pageid =1;
$start = 0;
}
$strSQL="SELECT A.ID, A.PREFIX_NAME, A.STD_FNAME, A.STD_LNAME, B.FAC_NAME_TH, C.PROGRAM_NAME_TH ";
$strSQL.="FROM uoc_std A LEFT JOIN ref_fac B ON(A.FAC_ID=B.FAC_ID) ";
$strSQL.="LEFT JOIN ref_program C ON(A.PROGRAM_ID=C.PROGRAM_ID) ";
$strSQL.="WHERE ((A.STD_FNAME LIKE '$txtfname%') AND (A.STD_LNAME LIKE '$txtlname%')) Limit $start, $pagesize";
$objQuery = mysql_query($strSQL, $conn);
$totalRow= mysql_num_rows($objQuery);
while ($row=mysql_fetch_assoc($objQuery)){
echo row[ID];}}
ทำไงต่อค่ะ
จะให้แสดง หน้าแรก ก่อนหน้า ถัดไป หน้าสุดท้าย (โดยพวกนี้เป็นลิงเมื่อกดถัดไป ก็โชว์หน้าถัดไป)
|
|
|
|
|
Date :
2009-09-14 16:26:16 |
By :
แนน |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ช่วยแนะนำหน่อย งานด่วน ตายลายหมดแล้ว
|
|
|
|
|
Date :
2009-09-14 20:28:37 |
By :
แนน |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<?php session_start();?>
<!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=utf-8" />
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
}
-->
</style>
<link href="sty.css" rel="stylesheet" type="text/css" />
<title>
</title>
<script language="JavaScript">
function disp(filesname) {
window.open( filesname, 'poppage', 'toolbars=0, scrollbars=1, location=0, statusbars=0, menubars=0, resizable=1, width=500, height=500' );
}
</script>
</head>
<body>
<table width="900" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="3" align="left" valign="top"><? include'head.php';?></td>
</tr>
<tr>
<td width="17" rowspan="6" align="left" valign="top"><? include'menu.php';?></td>
<td colspan="2" align="left" valign="top"><form method="get" id="frmSearch" name="frmSearch" action="search_std_name.php">
<table width="700" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="4"> </td>
</tr>
<tr>
<td colspan="4" align="center" valign="top" bgcolor="#FF9966" class="cs5">ตรวจสอบข้อมูลนักศึกษา</td>
</tr>
<tr>
<td colspan="4" align="center" valign="top" class="cs5"> </td>
</tr>
<tr>
<td width="63" align="right" valign="top"> </td>
<td width="281" align="left" valign="top"><span class="cs4">ชื่อ ::</span>
<input name="txtfname" type="text" id="txtfname" size="30" maxlength="30"></td>
<td width="287" align="left" valign="top"><span class="cs4">นามสกุล ::</span>
<input name="txtlname" type="text" id="txtlname" size="30" maxlength="30"></td>
<td width="59" align="left" valign="top"><input name="Submit" type="submit" class="b12" value="ค้นหา"></td>
</tr>
</table>
</form>
<table width="700" border="0" cellspacing="0" cellpadding="1">
<tr>
<td width="80" align="center" valign="top" bgcolor="#CCCCCC" class="cs4">รหัสนักศึกษา</td>
<td width="100" align="center" valign="top" bgcolor="#CCCCCC" class="cs4">ชื่อ</td>
<td width="86" align="center" valign="top" bgcolor="#CCCCCC" class="cs4">นามสกุล</td>
<td width="174" align="center" valign="top" bgcolor="#CCCCCC" class="cs4">คณะ</td>
<td width="160" align="center" valign="top" bgcolor="#CCCCCC" class="cs4">สาขา</td>
<td width="88" align="center" valign="top" bgcolor="#CCCCCC" class="cs4">ตรวจสอบ</td>
</tr><?
include("con_imfdb.php");
$txtfname=$_GET[txtfname];
$txtlname=$_GET[txtlname];
// echo $name=$_GET[txtfname];
if($txtfname!=''){
$pageid=$_GET[pageid];
$sql_select="select * from uoc_std WHERE ((STD_FNAME LIKE '$txtfname%') AND (STD_LNAME LIKE '$txtlname%'))";
$result= mysql_query( $sql_select, $conn );
$totalRows= mysql_num_rows($result);
$pagesize=20;
$totalpage=(int) ($totalRows / $pagesize);
if(($totalRows % $pagesize) !=0) {
$totalpage +=1;
}
if(isset($pageid)){
$start=$pagesize * ($pageid-1);
$pagesize=$pagesize+$pagesize;
}
else {
$pageid =1;
$start = 0;
}
// echo $start.$pagesize.$pageid;
$strSQL="SELECT A.ID, A.PREFIX_NAME, A.STD_FNAME, A.STD_LNAME, B.FAC_NAME_TH, C.PROGRAM_NAME_TH ";
$strSQL.="FROM uoc_std A LEFT JOIN ref_fac B ON(A.FAC_ID=B.FAC_ID)";
$strSQL.="LEFT JOIN ref_program C ON(A.PROGRAM_ID=C.PROGRAM_ID)";
$strSQL.="WHERE ((A.STD_FNAME LIKE '$txtfname%') AND (A.STD_LNAME LIKE '$txtlname%')) Limit $start, $pagesize";
$objQuery = mysql_query($strSQL, $conn);
$totalRow= mysql_num_rows($objQuery);
while ($row=mysql_fetch_assoc($objQuery)){
?>
<tr>
<td align="left" valign="top" class="cs3"><? echo $id=$row['ID'];?></td>
<td align="left" valign="top" class="cs3"> <? echo $row['PREFIX_NAME'];echo $row['STD_FNAME'];?></td>
<td align="left" valign="top" class="cs3"> <? echo $row['STD_LNAME'];?></td>
<td align="left" valign="top" class="cs3"> <? echo $row['FAC_NAME_TH'];?></td>
<td align="left" valign="top" class="cs3"> <? echo $row['PROGRAM_NAME_TH'];?></td>
<td align="center" valign="top" class="cs3"><a href="javascript:disp('show_std_name.php?id=<? echo $id;?>')"><img src="images/b_select.png" width="16" height="16" border="0" /></td>
</tr> <? } ?>
<tr><?php if ($totalRow == 0) { // Show if recordset empty ?>
<td colspan="6" align="left" valign="top" class="cs4">ไม่พบข้อมูลที่คุณต้องการ</td>
</tr><?php }// Show if recordset empty ?>
</table></td>
</tr>
<tr>
<td colspan="2" align="center" valign="top"><span class="cs4">Records <? echo $start+1; ?> to<? echo $totalRow;?> of <? echo $totalRows;?></span></td>
</tr>
<tr>
<td colspan="2" align="center" valign="top"><table width="314" border="0" cellspacing="2" cellpadding="0">
<tr>
<td align="center" valign="top" class="cs4"><a href="">หน้าแรก</a></td>
<td align="center" valign="top" class="cs4"><a href="search_std_name.php?pageid=<? echo $i; ?>">ก่อนหน้า</a></td>
<td align="center" valign="top" class="cs4"><a href="search_std_name.php?pageid=<? echo $i; ?>">ถัดไป</a></td>
<td align="center" valign="top" class="cs4"><a href="">หน้าสุดท้าย</a></td>
</tr><? } ?>
</table></td>
</tr>
<tr>
<td colspan="2" align="center" valign="top"> </td>
</tr>
<tr>
<td width="743" align="center" valign="top" bgcolor="#FF9966"><span class="cs5">©2008 ARIT | [email protected]</span></td>
<td width="140" align="center" valign="top"> </td>
</tr>
<tr>
<td colspan="2" align="center" valign="top"></td>
</tr>
</table>
</body>
</html>
|
|
|
|
|
Date :
2009-09-14 21:57:26 |
By :
แนน |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ยังอยู่ไหมครับ ทำได้หรือยัง
ตอบด้วย
|
|
|
|
|
Date :
2009-09-14 23:05:51 |
By :
NanoTHoro |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ดูจากโค๊ดน่าจะมี error นะครับ
|
|
|
|
|
Date :
2009-09-14 23:10:44 |
By :
plakrim |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เออเร่อชัวส์ครับคุณปลากิม ขนาดผมแค่อ่านยังเอ๋อเร๋อเลยครับ อิอิอิ
|
|
|
|
|
Date :
2009-09-14 23:37:16 |
By :
NanoTHoro |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ยังไม่ได้เลยค่ะ
|
|
|
|
|
Date :
2009-09-15 08:24:32 |
By :
แนน |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองดาวน์โหลดโคดของพี่วิน ไปทำตามดูครับ
|
|
|
|
|
Date :
2009-09-15 08:38:35 |
By :
panyapol |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ไม่ได้ตรงไหน มันฟ้องเออเร่อว่ายังงัยบ้าง
ลองแบบวิธีบ้านๆ ดูบ้างไหมครับ เอาโค้ดไปดูครับ
Code (PHP)
<?
if (!session_start()) session_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>บริษัท เอกธนภรณ์ 888 จำกัด</TITLE>
<META NAME="Generator" CONTENT="">
<META NAME="Author" CONTENT="Nano Thoro">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=TIS620">
<?
require("config.inc.php");
require("check_system.inc.php");
require("java/handler.js.php");
require("style/style_base.css.php");
require("style/style_font.css.php");
$_SESSION['timeStartLoad'] = "00:00:00";
$page = trim($_REQUEST['page']);
$sqlSelect = "SELECT bra_id FROM tb_branch";
$qry = mysql_query($sqlSelect);
$recCount = mysql_num_rows($qry);
if ($recCount == 0) {$totalPage = 0;} else {$totalPage = ceil($recCount / 20);}
if (vempty($page))
{
if ($totalPage > 0)
{
$page = $totalPage;
} else
{
$page = 1;
}
}
if (($totalPage > 0) and ($page > $totalPage)) $page = $totalPage;
?>
<script language = "JavaScript">
function change_page(btn)
{
var pageno = 0;
if (btn == "first")
{
pageno = 1;
} else if (btn == "prev")
{
pageno = document.form_send_value.pageno.value;
if (pageno > 1) {pageno--;}
} else if (btn == "next")
{
pageno = document.form_send_value.pageno.value;
if (pageno < document.form_send_value.total_page.value) {pageno++;}
} else if (btn == "last")
{
pageno = document.form_send_value.total_page.value;
} else
{
pageno = document.form_send_value.pageno.value;
}
document.form_send_value.pageno.value = pageno;
parent.frame_right.location.replace("view_branch.php?page=" + pageno);
}
</script>
</HEAD>
<BODY BACKGROUND="image/bg_body_main.png" ONCLICK="ehandler();" ONKEYPRESS="ehandler();">
<TABLE CELLPADDING="0" CELLSPACING="0" BORDER="0" VALIGN="top" ALIGN="center" WIDTH="780">
<TR><TD HEIGHT="10"></TD></TR>
<TR>
<TD VALIGN="top" ALIGN="center" WIDTH="780">
<TABLE CELLPADDING="0" CELLSPACING="0" BORDER="1" VALIGN="top" ALIGN="center" WIDTH="775" HEIGHT="45">
<TR>
<TD WIDTH="560" HEIGHT="45" VALIGN="top" ALIGN="right" BACKGROUND="image/view_head.jpg">
<FONT CLASS="font_hdata">แสดงข้อมูลสาขา </FONT>
</TD>
</TR>
</TABLE>
<?
$goto = ($page - 1) * 20;
$sqlSelect = "SELECT bra_id, bra_name, bra_telephone FROM tb_branch LIMIT $goto, 20";
$qry = mysql_query($sqlSelect);
?>
<TABLE CELLPADDING="0" CELLSPACING="1" BORDER="0" VALIGN="top" ALIGN="center" WIDTH="775" HEIGHT="25">
<TR BGCOLOR="#999999">
<TH VALIGN="middle" ALIGN="center" WIDTH="150">รหัสสาขา</TH>
<TH VALIGN="middle" ALIGN="center" WIDTH="350">ชื่อสาขา</TH>
<TH VALIGN="middle" ALIGN="center" WIDTH="185">เบอร์โทรศัพท์</TH>
<TH VALIGN="middle" ALIGN="center" COLSPAN="2">ปรับปรุง</TH>
<TH VALIGN="middle" ALIGN="center" WIDTH="30">
<IMG SRC="image/add.png" WIDTH="24" HEIGHT="24" BORDER="0" ALT="เพิ่มข้อมูลใหม่" STYLE="cursor:hand" ONCLICK="parent.frame_right.location.replace('add_branch.php')">
</TH>
</TR>
<?
$bgColor1 = "#dddddd";
$bgColor2 = "#bbbbbb";
for ($i = 0; $i < 20; $i++)
{
$result = mysql_fetch_array($qry);
$braID = $result['bra_id'];
$braName = $result['bra_name'];
$braTelephone = $result['bra_telephone'];
if (($braID != "") or ($braID != null))
{
echo "<TR BGCOLOR='$bgColor1'><TD VALIGN='middle' ALIGN='left' HEIGHT='25' WIDTH='150'>$braID</TD>"
. "<TD VALIGN='middle' ALIGN='left' HEIGHT='25' WIDTH='350'>$braName</TD>"
. "<TD VALIGN='middle' ALIGN='left' HEIGHT='25' WIDTH='185'>$braTelephone</TD>";
echo "<TD VALIGN='middle' ALIGN='center' WIDTH='30' HEIGHT='25' BGCOLOR='$bgColor2'>"
. "<IMG SRC='image/browse.png' WIDTH='24' HEIGHT='24' BORDER='0' ALT='ดูรายละเอียดอื่นๆ' STYLE='cursor:hand' ONCLICK='parent.frame_right.location.replace(\"show_branch.php?s_bra_id=$braID\")'></TD>";
echo "<TD VALIGN='middle' ALIGN='center' WIDTH='30' HEIGHT='25' BGCOLOR='$bgColor2'>"
. "<IMG SRC='image/edit.png' WIDTH='24' HEIGHT='24' BORDER='0' ALT='แก้ไขข้อมูล' STYLE='cursor:hand' ONCLICK='parent.frame_right.location.replace(\"edit_branch.php?s_bra_id=$braID\")'></TD>";
echo "<TD VALIGN='middle' ALIGN='center' WIDTH='30' HEIGHT='25' BGCOLOR='$bgColor2'>"
. "<IMG SRC='image/delete.png' WIDTH='24' HEIGHT='24' BORDER='0' ALT='ลบข้อมูล' STYLE='cursor:hand' ONCLICK='parent.frame_right.location.replace(\"delete_branch.php?s_bra_id=$braID\")'>"
. "</TD></TR>";
} else
{
echo "<TR BGCOLOR='$bgColor1'><TD VALIGN='middle' ALIGN='left' HEIGHT='25' WIDTH='150'> </TD>"
. "<TD VALIGN='middle' ALIGN='left' HEIGHT='25' WIDTH='350'> </TD>"
. "<TD VALIGN='middle' ALIGN='left' HEIGHT='25' WIDTH='185'> </TD>";
echo "<TD VALIGN='middle' ALIGN='center' WIDTH='30' HEIGHT='25' BGCOLOR='$bgColor2'> </TD>";
echo "<TD VALIGN='middle' ALIGN='center' WIDTH='30' HEIGHT='25' BGCOLOR='$bgColor2'> </TD>";
echo "<TD VALIGN='middle' ALIGN='center' WIDTH='30' HEIGHT='25' BGCOLOR='$bgColor2'> </TD></TR>";
}
if ($bgColor1 == "#dddddd")
{
$bgColor1 = "#cccccc";
$bgColor2 = "#aaaaaa";
} else
{
$bgColor1 = "#dddddd";
$bgColor2 = "#bbbbbb";
}
}
echo "</TABLE>";
?>
<TABLE CELLPADDING="0" CELLSPACING="0" BORDER="0" VALIGN="top" ALIGN="center" WIDTH="775" HEIGHT="25">
<TR>
<TD WIDTH="775" HEIGHT="25" VALIGN="top" ALIGN="left">
<FORM NAME="form_send_value">
<?
if ($totalPage > 0)
{
?>
<IMG SRC="image/firstpage.png" WIDTH="16" HEIGHT="13" BORDER="0" ALT="แรกสุด" ONCLICK="change_page('first')" STYLE="cursor:hand">
<IMG SRC="image/prevpage.png" WIDTH="8" HEIGHT="13" BORDER="0" ALT="ก่อนหน้า" ONCLICK="change_page('prev')" STYLE="cursor:hand">
<SELECT NAME="pageno" ONCHANGE="change_page('slepage')">
<OPTION VALUE=<?=$page?>><?=$page?></OPTION>
<OPTION VALUE=<?=$page?>>-</OPTION>
<?
for ($i = 1; $i <= $totalPage; $i++)
{
echo "<OPTION VALUE=$i>$i</OPTION> \n";
}
?>
</SELECT>
<IMG SRC="image/nextpage.png" WIDTH="8" HEIGHT="13" BORDER="0" ALT="ถัดไป" ONCLICK="change_page('next')" STYLE="cursor:hand">
<IMG SRC="image/lastpage.png" WIDTH="16" HEIGHT="13" BORDER="0" ALT="ท้ายสุด" ONCLICK="change_page('last')" STYLE="cursor:hand">
<?
} else
{
echo "ไม่มีข้อมูล";
}
?>
<INPUT TYPE="hidden" NAME="total_page" ID="total_page" VALUE=<?=$totalPage?>>
</FORM>
</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>
|
|
|
|
|
Date :
2009-09-15 09:27:20 |
By :
NanoTHoro |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลืมบอกไปว่าไฟล์ที่ต้อง require คือไฟล์ config.inc.php เป็นไฟล์ที่กำหนดรายละเอียดของดาต้าเบสที่ใช้ติดต่อ หากเราติดต่อดาต้าเบสในหน้านี้เลยก็ไม่ต้อง require เข้ามานะครับ ส่วนไฟล์อื่น ๆ ไม่ต้อง require เข้ามานะครับ เดี๋ยวมันจะหาไฟล์ไม่เจอ ถ้ายังไม่เข้าใจพอลองไปดูที่ลิงค์นี้ครับ
https://www.thaicreate.com/php/forum/031218.html
หวังว่าคงทำได้นะครับ
|
|
|
|
|
Date :
2009-09-15 09:30:51 |
By :
NanoTHoro |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ได้แล้วค่ะ
|
|
|
|
|
Date :
2009-09-15 09:45:56 |
By :
แนน |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ยินดีด้วยครับ
|
|
|
|
|
Date :
2009-09-15 09:52:29 |
By :
NanoTHoro |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|