ยินดีต้อนรับคุณ, บุคคลทั่วไป กรุณา เข้าสู่ระบบ หรือ ลงทะเบียน

เข้าสู่ระบบด้วยชื่อผู้ใช้ รหัสผ่าน และระยะเวลาในเซสชั่น

ThaiSEOBoard.comพัฒนาเว็บไซต์ProgrammingCode แบ่งหน้าใช้ไม่ได้กับ PHP 5
หน้า: [1]   ลงล่าง
พิมพ์
ผู้เขียน หัวข้อ: Code แบ่งหน้าใช้ไม่ได้กับ PHP 5  (อ่าน 1918 ครั้ง)
0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้
mikeyx
Verified Seller
เจ้าพ่อบอร์ดเสียว
*

พลังน้ำใจ: 268
ออฟไลน์ ออฟไลน์

กระทู้: 4,009



ดูรายละเอียด เว็บไซต์
« เมื่อ: 29 เมษายน 2008, 13:50:37 »

โค๊ด:
Create Database member;

CREATE TABLE member (
id int(4) NOT NULL auto_increment,
user varchar(30) NOT NULL,
name varchar(50) NOT NULL,
email varchar(50) NOT NULL,
tel varchar(50) NOT NULL,
PRIMARY KEY (id)
);

Sample1.php

<html>
<head>
<body bgcolor="#FFFFFF">
<br>
<table width="72%" border="1" align="center" cellspacing="0" cellpadding="0" height="23">
<tr>
<td width="8%">
<div align="center">id</div>
</td>
<td width="14%">
<div align="center">user</div>
</td>
<td width="30%">
<div align="center">name</div>
</td>
<td width="26%">
<div align="center">email</div>
</td>
<td width="22%">
<div align="center">tel</div>
</td>
</tr>
</table>
<?
$host="localhost";
$username="";
$pass_word="";
$db="member";
mysql_connect( $host,$username,$pass_word) or die ("ติดต่อกับฐานข้อมูล Mysql ไม่ได้ ");
mysql_select_db($db) or die("เลือกฐานข้อมูลไม่ได้");

$sql = "select * From member ";
/* ตั้งค่า แสดงผลต่อหน้า $Per_Page */

$Per_Page =2;
if(!$Page)
$Page=1;

$Prev_Page = $Page-1;
$Next_Page = $Page+1;

$result = mysql_query($sql);
$Page_start = ($Per_Page*$Page)-$Per_Page;
$Num_Rows = mysql_num_rows($result);

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;

if(($Page>$Num_Pages) || ($Page<0))
print "<center><b>จำนวน $Page มากกว่า $Num_Pages ยังไม่มีข้อความ<b></center>";
$sql .= " Where 1 Order by id Desc LIMIT $Page_start , $Per_Page";
//ส่วนแสดงผล
$result = mysql_query($sql);
While($row= mysql_fetch_array($result)){
$id = $row["id"];
$user = $row["user"];
$name = $row["name"];
$email = $row["email"];
$tel = $row["tel"];

?>
<table width="72%" border="1" align="center" cellspacing="0" cellpadding="0" height="23">
<tr>
<td width="8%">
<div align="center">
<?= $id;?>
</div>
</td>
<td width="14%">
<?= $user;?>
</td>
<td width="30%">
<?= $name;?>
</td>
<td width="27%">
<?= $email;?>
</td>
<td width="21%">
<?= $tel;?>
</td>
</tr>
</table>
<?}?>
<div align="center"><br>
มีจำนวน Recored ทั้งหมด
<?= $Num_Rows;?>
รวมทั้งหมด : <b>
<?=$Num_Pages;?>
</b> หน้า :
<?/* สร้างปุ่มย้อนกลับ */
if($Prev_Page)
echo " <a href='$PHP_SELF?Page=$Prev_Page'><< ย้อนกลับ </a>";
for($i=1; $i<$Num_Pages; $i++){
if($i != $Page)
echo "[<a href='$PHP_SELF?Page=$i'>$i</a>]";
else
echo "<b> $i </b>";
}
/*สร้างปุ่มเดินหน้า */
if($Page!=$Num_Pages)
echo "<a href ='$PHP_SELF?Page=$Next_Page'> หน้าถัดไป>> </a>";

?>
</div>
</body>
</html>





 Kiss รวบกวนผู้รู้ด้วยค๊าบ
บันทึกการเข้า
EThaiZone
เจ้าพ่อโลลิค่อน
เจ้าพ่อบอร์ดเสียว
*

พลังน้ำใจ: 321
ออฟไลน์ ออฟไลน์

กระทู้: 12,516



ดูรายละเอียด
« ตอบ #1 เมื่อ: 29 เมษายน 2008, 13:56:50 »

โค๊ด:
Sample1.php

<html>
<head>
<body bgcolor="#FFFFFF">
<br>
<table width="72%" border="1" align="center" cellspacing="0" cellpadding="0" height="23">
<tr>
<td width="8%">
<div align="center">id</div>
</td>
<td width="14%">
<div align="center">user</div>
</td>
<td width="30%">
<div align="center">name</div>
</td>
<td width="26%">
<div align="center">email</div>
</td>
<td width="22%">
<div align="center">tel</div>
</td>
</tr>
</table>
<?
$host="localhost";
$username="";
$pass_word="";
$db="member";
mysql_connect( $host,$username,$pass_word) or die ("ติดต่อกับฐานข้อมูล Mysql ไม่ได้ ");
mysql_select_db($db) or die("เลือกฐานข้อมูลไม่ได้");

$sql = "select * From member ";
/* ตั้งค่า แสดงผลต่อหน้า $Per_Page */

$Per_Page =2;
if(!$_GET['Page'])
$_GET['Page']=1;

$Prev_Page = $_GET['Page']-1;
$Next_Page = $_GET['Page']+1;

$result = mysql_query($sql);
$Page_start = ($Per_Page*$_GET['Page'])-$Per_Page;
$Num_Rows = mysql_num_rows($result);

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;

if(($_GET['Page']>$Num_Pages) || ($_GET['Page']<0))
print "<center><b>จำนวน ".$_GET['Page']." มากกว่า $Num_Pages ยังไม่มีข้อความ<b></center>";
$sql .= " Where 1 Order by id Desc LIMIT $Page_start , $Per_Page";
//ส่วนแสดงผล
$result = mysql_query($sql);
While($row= mysql_fetch_array($result)){
$id = $row["id"];
$user = $row["user"];
$name = $row["name"];
$email = $row["email"];
$tel = $row["tel"];

?>
<table width="72%" border="1" align="center" cellspacing="0" cellpadding="0" height="23">
<tr>
<td width="8%">
<div align="center">
<?= $id;?>
</div>
</td>
<td width="14%">
<?= $user;?>
</td>
<td width="30%">
<?= $name;?>
</td>
<td width="27%">
<?= $email;?>
</td>
<td width="21%">
<?= $tel;?>
</td>
</tr>
</table>
<?}?>
<div align="center"><br>
มีจำนวน Recored ทั้งหมด
<?= $Num_Rows;?>
รวมทั้งหมด : <b>
<?=$Num_Pages;?>
</b> หน้า :
<?/* สร้างปุ่มย้อนกลับ */
if($Prev_Page)
echo " <a href='$PHP_SELF?Page=$Prev_Page'><< ย้อนกลับ </a>";
for($i=1; $i<$Num_Pages; $i++){
if($i != $_GET['Page'])
echo "[<a href='$PHP_SELF?Page=$i'>$i</a>]";
else
echo "<b> $i </b>";
}
/*สร้างปุ่มเดินหน้า */
if($_GET['Page']!=$Num_Pages)
echo "<a href ='$PHP_SELF?Page=$Next_Page'> หน้าถัดไป>> </a>";

?>
</div>
</body>
</html>
บันทึกการเข้า

mikeyx
Verified Seller
เจ้าพ่อบอร์ดเสียว
*

พลังน้ำใจ: 268
ออฟไลน์ ออฟไลน์

กระทู้: 4,009



ดูรายละเอียด เว็บไซต์
« ตอบ #2 เมื่อ: 29 เมษายน 2008, 14:06:43 »

อ๋อลืมไป ต้องมี

GET
 ขอบคุณมากครับ Kiss
บันทึกการเข้า
หน้า: [1]   ขึ้นบน
พิมพ์