คนละตัวกันครับ ของ PostSmiles.com ตามโค๊ดด้านล่างนี้เลยครับ
โค๊ด:
<style type="text/css">
<!--
span.split-page-present {
padding: 0px 5px;
margin: 0px 1px;
border: 1px solid #999999;
background-color: #999999;
line-height: 1.5em;
font-size: 0.9em;
color: #FFFFFF;
}
span.split-page-select {
color: #000000;
}
span.split-page-select a:link {
padding: 0px 5px;
margin: 0px 1px;
border: 1px solid #E5E5E5;
background-color: #E5E5E5;
line-height: 1.5em;
font-size: 0.9em;
color: #000000;
text-decoration: none;
}
span.split-page-select a:visited {
padding: 0px 5px;
margin: 0px 1px;
border: 1px solid #E5E5E5;
background-color: #E5E5E5;
line-height: 1.5em;
font-size: 0.9em;
color: #000000;
text-decoration: none;
}
span.split-page-select a:hover {
padding: 0px 5px;
margin: 0px 1px;
border: 1px solid #999999;
background-color: #999999;
line-height: 1.5em;
font-size: 0.9em;
color: #FFFFFF;
text-decoration: none;
}
div#wrapper-split-page {
margin: 10px 20px 10px 20px;
text-align: right;
}-->
</style>
<?php
# Function: Display split pages : link normal function split_page($geturl = "", $rows_page = "", $totalpage = "", $startpage = "", $endpage = "", $page = "") { if (!empty($rows_page)) { $total_all_records = number_format($rows_page, ','); echo " <strong>Page:</strong> {$page} of {$totalpage} (Total: {$total_all_records} items) "; if (!empty($rows_page)) { if ($page > 1) { $back = $page - 1; echo "<a href=\"{$geturl}&page=1\"><img src=\"images/icon/icon-first-page.png\" title=\"First Page\" width=\"10\" height=\"12\" border=\"0\" align=\"absmiddle\" /></a> "; echo "<a href=\"{$geturl}&page={$back}\"><img src=\"images/icon/icon-prev-page.png\" title=\"Previous Page\" width=\"7\" height=\"12\" border=\"0\" align=\"absmiddle\" /></a> "; if ($startpage > 1) { echo " ... "; } } else { echo "<img src=\"images/icon/icon-first-page-dummy.png\" title=\"First Page\" width=\"10\" height=\"12\" border=\"0\" align=\"absmiddle\" /> "; echo "<img src=\"images/icon/icon-prev-page-dummy.png\" title=\"Previous Page\" width=\"7\" height=\"12\" border=\"0\" align=\"absmiddle\" /> "; if ($startpage > 1) { echo " ... "; } } # Display number pages for link and select for ($i = $startpage; $i <= $endpage; $i++) { if ($i == $page ) { echo "<span class=\"split-page-present\">{$i}</span>"; } else { echo "<span class=\"split-page-select\"><a href=\"{$geturl}&page={$i}\">{$i}</a></span>"; } } if ($page < $totalpage) { $next = $page + 1; if ($endpage < $totalpage) { echo " ... "; } echo " <a href=\"{$geturl}&page={$next}\"><img src=\"images/icon/icon-next-page.png\" title=\"Next Page\" width=\"7\" height=\"12\" align=\"absmiddle\" /></a>"; echo " <a href=\"{$geturl}&page={$totalpage}\"><img src=\"images/icon/icon-last-page.png\" title=\"Last Page\" width=\"10\" height=\"12\" align=\"absmiddle\" /></a>"; } else { if ($endpage < $totalpage) { echo " ... "; } echo " <img src=\"images/icon/icon-next-page-dummy.png\" title=\"Next Page\" width=\"7\" height=\"12\" align=\"absmiddle\" />"; echo " <img src=\"images/icon/icon-last-page-dummy.png\" title=\"Last Page\" width=\"10\" height=\"12\" align=\"absmiddle\" />"; } } //echo " <span class=\"split-page\">{ <a href=\"{$geturl}&page=all\">Show All</a> }</span>"; } // end if: !empty($rows_page) } # Process data : use MySQL class for any website $link=mysql_connect("localhost","root",""); mysql_select_db("thailocation"); # Configuration variable for split pages $pagelen = 20; // config : set value for display per pages $range = 5; // config : number page for show in link $page = $_GET['page']; # Mode SQL Command : Select for count data in condition $sql = " SELECT "; // $sql .= " ar_id "; $sql .= " FROM "; $sql .= " tbl_article "; // end if : $cate_id != "all" # Execute query command $res['select_all_data'] = mysql_query($sql); # Calculate variable for split pages $rows_page = mysql_num_rows($res['select_all_data']); $totalpage = ceil($rows_page / $pagelen); # Check : if (empty($page)) { $page = 1; } // if ((!ereg("^[0-9]+$", "$page")) && ($page != "all")) { $page = 1; } // if ($page > $totalpage) { $page = 1; } // $goto = ($page - 1) * $pagelen; $startpage = $page - $range; $endpage = $page + $range; if ($startpage <= 1) { $startpage = 1; } if ($endpage >= $totalpage) { $endpage = $totalpage; } # Mode SQL Command : Select data for split pages (main data in condition) $sql = " SELECT "; $sql .= " * "; $sql .= " FROM "; $sql .= " tbl_article "; $sql .= " ORDER BY "; $sql .= " ar_id "; $sql .= " DESC "; if ($page != "all") { // Display all page : { Show All } $sql .= " LIMIT $goto , $pagelen "; } # Execute query command $res['select_split_page'] = mysql_query($sql); # Get number of rows in result : per page $count_rows = mysql_num_rows($res['select_split_page']);
###########Show data#################################$i = 1;$cols=2; //Colums$c=$cols;
echo "<table>\n<tr>";
while ( $rs = mysql_fetch_array( $res['select_split_page'] ) ) {
$c--;
echo "<td width='50%' valign='top'>";
echo "<table width='100%' border='0' cellspacing='0' cellpadding='2'> <tr>"; if($rs['ar_picture']){
echo "<td width='10%' valign='top'><img src='datafiles/article/".$rs['ar_picture']."' align='absmiddle' style='border:1px solid #666666;'></td>"; }
echo "<td width='90%' valign='top'>
<a href='".WEB_URL."/article/".$_REQUEST['ar_type_name']."-".eregi_replace(" ","+",$rs['ar_topic'])."-".$rs['ar_id'].".html' target='_blank' >
<strong><u>".$rs['ar_topic']."</u></strong>
<br><font style='font-size:11px; color:#666666'>".$rs['ar_fdetail']."...</font></a>
</td>"; echo "</tr> "; echo " <tr>
<td height='10' style='border-bottom: dotted 1px #E1E1E1' colspan='2'></td>
</tr> ";
echo "</table>";
echo "</td>"; //
if ($c==0) {
echo "</tr><tr>";
$c=$cols;
}
}
echo "</tr>\n</table>\n";############################################
?>
<div id="wrapper-split-page">
<?php# Call function split_pages$geturl = WEB_URL."/article_list/".$_REQUEST['ar_type_name']."-".$_REQUEST['ar_type']."&tag=".$_REQUEST['tag']."";
if ($page == "all") { // Display all page : { Show All } $total_all_records = number_format($rows_page, ','); echo "<span class=\"split-page\"><strong>Show All</strong> { {$total_all_records} items }</span>";
} else { // if page = 1, 2, 3 split_page($geturl, $rows_page, $totalpage, $startpage, $endpage, $page); // call function split_pages()}?>
</div>ลอง เอาไปศึกษาประยุกต์ใช้ดูนะครับ ถ้าจะให้ดีควรแยกโค๊ด Function และ stylesheets ออกมาเป็นไฟล์ แล้วค่อย Include มาใช้จะทำให้โค๊ดดูง่ายขึ้นครับ


5:34 PM
Computer !
0 comments:
Post a Comment