|
|
|
การแบ่งหน้า มีโค้ดแล้วแต่ทำไม่เป็น (มือใหม่) กำลังทำโปรเจคอยู่ค่ะ ดึงข้อมูลมาโชว์ได้แล้ว |
|
|
|
|
|
|
|
กำลังทำโปรเจคอยู่ค่ะ ดึงข้อมูลมาโชว์ได้แล้ว แต่ยังแบ่งหน้าไม่ได้ค่ะ รบกวนช่วยดูให้ทีนะคะ ขอบคุณค่ะ
------โค้ดดึงข้อมูล-----
<center><table border="1" bordercolor="#FF0000" bgcolor="#FFFFCC"></center>
<tr>
<td bgcolor="#CC0000"><b><center>รหัส</center></b></td>
<td bgcolor="#CC0000"><b><center>ชื่ออาหาร</center></b></td>
<td bgcolor="#CC0000"><b><center>รูป</b></center></td>
<td bgcolor="#CC0000"><b><center>ราคา</b></center></td>
<td bgcolor="#CC0000"> <b><center>ประเภท</b></center></td>
</tr>
<?
include("connect2.php");
$sql=mysql_query("select * from food where Type_id='1'");
while($row=mysql_fetch_array($sql))
{
echo '<tr><td>'.$row[0].'</td>';
echo '<td>'.$row[1].'</td>';
echo '<td><img src='.$row[2].' width=200 height=120></td>';
echo '<td>'.$row[3].'</td>';
echo '<td>'.$row[4].'</td></tr>';
}
?>
</table>
</body>
</html>
------โค้ดแบ่งหน้า-----
<html>
<head>
<title>การแบ่งหน้าข้อมูล</title>
<style type="text/css">
//<!--
A:link { font-family: Arial, Helvetica, sans-serif; font-size: 10pt; text-decoration: none; color: blue }
A:visited { font-family: Arial, Helvetica, sans-serif; font-size: 10pt; text-decoration: none; color: blue }
A:hover { font-family: Arial, Helvetica, sans-serif; font-size: 10pt; text-decoration: none; color: red }
.Small { font-family: Arial, Helvetica, sans-serif; font-size: 10pt; text-decoration: none }
//?>
</style>
</head>
<body bgcolor="#F1F1F1">
<p class="Small">
<?php
/* เรียกแฟ้มข้อมูล phpConfig.php มาใช้งาน */
include( "phpConfig.php" );
/* สร้าง Connection ติดต่อกับ MySQL Server เก็บไว้กับตัวแปร $conn */
$conn = mysql_connect( $ServerName, $UserName, $UserPassword );
if ( ! $conn )
die( "ไม่สามารถติดต่อกับ MySQL ได้" );
/* เลือกใช้งานฐานข้อมูลที่กำหนดไว้กับตัวแปร $DataBaseName */
mysql_select_db( $DataBaseName, $conn )
or die ( "ไม่สามารถเลือกใช้งานฐานข้อมูล $DataBaseName ได้" );
$strSQL = ("select * from food where Type_id='1'");
$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;
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 "จำนวน $Page มากกว่า $Num_Pages";
$strSQL .= " LIMIT $Page_start, $Per_Page";
$result = mysql_query( $strSQL );
while ( $rs = mysql_fetch_array( $result ) )
{
echo "$rs[ID] <br>\n";
}
?>
<p class="Small">
รวมทั้งหมด <b><?php echo $Num_Rows; ?></b> เรคคอร์ด <b><?php echo $Num_Pages; ?></b> หน้า:
<?php
/* สร้างปุ่มย้อนกลับ */
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>";
mysql_close( $conn );
?>
Tag : - - - -
|
|
|
|
|
|
Date :
30 พ.ย. 2550 13:05:47 |
By :
kukkikonline |
View :
1468 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!isset($start)){
$start= 0;
}
$limit = '10';
//------------ query ข้อมูลค่ะ หาจำนวนแถวทั้งหมด
$sql = "select Train_Id,Origin_Station,Destination_Station,Dep_Time,Arr_Time from traintime_tablego";
$result=mysql_db_query($dbname,$sql);
$numrow=mysql_num_rows($result);
//-----------query ข้อมูลเพื่อแสดงผลเป็นหน้าๆ
$psql = "select Train_Id,Origin_Station,Destination_Station,Dep_Time,Arr_Time from traintime_tablego limit $start,$limit";
$resultp=mysql_db_query($dbname,$psql);
$record=mysql_fetch_array($resultp);
while ($record=mysql_fetch_array($resultp)) {
//-- วนลูปแสดงข้อมูล ...
...
---<td></td>
}
<tr>
<td>
//-------------- ตรงนี้จะแสดงการแบ่งหน้าค่ะ อยู่ในเทเบิลแถวสุดท้ายซึ่งไม่ได้วนลูปตามไปด้วย
<?
$page= ceil($numrow/$limit); // เอา record ทั้งหมด หารด้วย จำนวนที่จะแสดงของแต่ละหน้า
echo "จำนวนทั้งหมด ".($page)." หน้า ----- ";
if(!isset($thispage)){ $thispage=1; }
$prev=$thispage-1;
$next=$thispage+1;
if($prev!=0)
{
echo"<a href='?start=0&page=1'> << </a>";
echo" | <a href='?start=".$limit*($thispage-2)."&thispage=".($thispage-1)."'>[ ก่อนหน้า]</a> | ";}
else{}
echo"หน้า ";
echo $thispage;
if($next <= $page)
{ echo" | <a href='?start=".$limit*($thispage)."&thispage=".($thispage+1)."'> [ถัดไป]</a> |";
echo"<a href='?start=".$limit*($page-1)."&thispage=".($pageschool)."'> >> </a>";
}
?>
</td>
</tr>
-----
ลองศึกษาโค้ดข้างบนเป็นตัวอย่างนะคะ
|
|
|
|
|
Date :
30 พ.ย. 2550 14:28:54 |
By :
hobbits |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|