|
|
|
เวลาเพิ่มข้อมูลลงไปมันจะยาว ต้องการที่จะแบ่งหน้าให้มันแสดงแค่หน้าละ 10 แถว |
|
|
|
|
|
|
|
Code (PHP)
<?php
$host="localhost";
$user="root";
$passwd="d2127z";
$dbname="td2011";
mysql_connect($host,$user,$passwd) or die("ติดต่อhostไม่ได้");
mysql_select_db($dbname)or die("ติดต่อฐานข้อมูลไม่ได้ไม่ได้");
$sql="select*from repair_work";
mysql_query("SET character_set_result=tis602_thai_ci");
mysql_query("SET character_set_=client=tis602_thai_ci");
mysql_query("SET character_set_connection='tis620_thai_ci'");
$sqlquery=mysql_db_query($dbname,$sql);
print"<h3>รายการแจ้งซ่อมทั้งหมด".mysql_num_rows($sqlquery)."รายการดังนี้</h3>";
print"<table>";
print"<tr bgcolor=0066FF>";
print"<td align=center>ลำดับที่</td>";
print"<td align=center>ชื่อผู้แจ้งซ่อม</td>";
print"<td align=center>วันที่</td>";
print"<td align=center>เวลา</td>";
print"<td align=center>หน่วยงาน</td>";
print"<td align=center>เบอร์โทรศัพ์ภายใน</td>";
print"<td align=center>อุปกรณ์</td>";
print"<td align=center>อาการ</td>";
print"</tr>";
while($row=mysql_fetch_row($sqlquery))
{
print"<tr bgcolor=00CCFF>";
print"<td>".$row[0]."</td>";
print"<td>".$row[1]."</td>";
print"<td>".$row[2]."</td>";
print"<td>".$row[3]."</td>";
print"<td>".$row[4]."</td>";
print"<td>".$row[5]."</td>";
print"<td>".$row[6]."</td>";
print"<td>".$row[7]."</td>";
print"<td>".$row[8]."</td>";
print"<td>".$row[9]."</td>";
print"<td>".$row[10]."</td>";
}
print"</table>";
echo displayPaging( $total, $limit, $pagenumber, $baseurl );
function displayPaging( $total, $limit, $pagenumber, $baseurl )
{
// how many page numbers to show in list at a time
$showpages = "10"; // 1,3,5,7,9...
// set up icons to be used
$icon_path = 'icons/';
$icon_param = 'align="middle" style="border:0px;" ';
$icon_first= '[First page]';
$icon_last= '[Lastpage]';
$icon_previous= '<< Previous';
$icon_next= 'Next >>';
///////////////////
///////////////////
// do calculations
@$pages = ceil($total / $limit);
$offset = ($pagenumber * $limit) - $limit;
$end = $offset + $limit;
// prepare paging links
$html .= '<div id="pageLinks">';
// if first link is needed
if($pagenumber > 1) { $previous = $pagenumber -1;
$html .= '<a href="'.$baseurl.'1">'.$icon_first.'</a> ';
}
// if previous link is needed
if($pagenumber > 2) { $previous = $pagenumber -1;
$html .= '<a href="'.$baseurl.''.$previous.'">'.$icon_previous.'</a> ';
}
// print page numbers
if ($pages>=2) { $p=1;
$html .= "| Page: ";
$pages_before = $pagenumber - 1;
$pages_after = $pages - $pagenumber;
$show_before = floor($showpages / 2);
$show_after = floor($showpages / 2);
if ($pages_before < $show_before){
$dif = $show_before - $pages_before;
$show_after = $show_after + $dif;
}
if ($pages_after < $show_after){
$dif = $show_after - $pages_after;
$show_before = $show_before + $dif;
}
$minpage = $pagenumber - ($show_before+1);
$maxpage = $pagenumber + ($show_after+1);
if ($pagenumber > ($show_before+1) && $showpages > 0) {
$html .= " ... ";
}
while ($p <= $pages) {
if ($p > $minpage && $p < $maxpage) {
if ($pagenumber == $p) {
$html .= " <b>".$p."</b>";
} else {
$html .= ' <a href="'.$baseurl.$p.'">'.$p.'</a>';
}
}
$p++;
}
if ($maxpage-1 < $pages && $showpages > 0) {
$html .= " ... ";
}
}
// if next link is needed
if($end < $total) { $next = $pagenumber +1;
if ($next != ($p-1)) {
$html .= ' | <a href="'.$baseurl.$next.'">'.$icon_next.'</a>';
} else {$html .= ' | ';}
}
// if last link is needed
if($end < $total) { $last = $p -1;
$html .= ' <a href="'.$baseurl.$last.'">'.$icon_last.'</a>';
}
$html .= '</div>';
// return paging links
return $html;
}
mysql_close();
?>
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2012-05-02 17:14:50 |
By :
UHU |
View :
791 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|