MySQL pagination class (with page-bar feature)

Source: Internet
Author: User
The code is as follows Copy Code
/function fenyezhixin ($table, $pagesize = "", $paixu = "", $do = "", $wwhere = "") {
if ($table = = "News_fabu") or ($table = = "Product_fabu") or ($table = = "message") or ($table = = "Down_fabu") or ($table = = "Kucun")) {
$query = @mysql_query ("select * from $table $wwhere");
$pagesize = $pagesize;
$sum = mysql_num_rows ($query);
if ($sum = = 0) {
$pagesize = 1;
}
if ($pagesize = = "0") {
$sum = "1";
}
if (@ ($sum% $pagesize) = = 0) {
$total = @ (int) ($sum/$pagesize);
}else{
$total = @ (int) ($sum/$pagesize) + 1;
}
if ($total = = 0) {$total = 1;}
if (Isset ($_get[' page ')) {
$p = (int) $_get[' page '];
}else{
$p = 1;
}
$start = $pagesize * ($p-1);
$query = @mysql_query ("select * from $table $wwhere ORDER by $paixu limit $start, $pagesize") or Die ("Data query failed 2!");
if ($do = = 1) {
$queryarray = Array ($query, $total, $sum, $p);
return $queryarray;
}
if ($do = = 2) {
$parray = Array ($total, $sum, $p);
return $parray;
}
}else{
$query = @mysql_query ("select * from $table $wwhere ORDER by $paixu limit $pagesize") or Die ("Data query failed 1!");
if ($do = = 1) {
$queryarray = Array ($query, $total, $sum, $p);
return $queryarray;
}
if ($do = = 2) {
$parray = Array ($total, $sum, $p);
return $parray;
}
}
}
Back to Page Bar
function Fenyedaohang ($total = "", $sum = "", $p = "", $menut = "") {
$w = substr ($menut, Strrpos ($menut, "&") +1,2);
$WR = substr ($menut, Strrpos ($menut, "=") +1,strlen ($menut));
$pindao = $_server["Script_name"]; $pinstrlen = Strrpos ($pindao, "/"); $pindao = substr ($pindao, $pinstrlen +1,strlen ($pindao));
if ($w = = "PR") {
$queryr = mysql_query ("Select Feiye.feiye_what from Feiye where feiye.feiye_page = ' $pindao '");
$rows = Mysql_fetch_row ($queryr); $rrows = $rows [0];
if (empty ($rrows)) {
mysql_query ("INSERT INTO ' Feiye ' (' feiye_page ', ' feiye_what ') VALUES (' $pindao ', ' $WR ')");
echo "<meta http-equiv= ' refresh ' content= ' 0 ' >";
}else{
if ($WR!= $rrows) {
mysql_query ("Update" Feiye ' Set ' feiye_what ' = ' $wr ' WHERE (' feiye_page ' = ' $pindao '));
echo "<meta http-equiv= ' refresh ' content= ' 0 ' >";
}
}
}
if ($w = = "Ne") {
$queryr = mysql_query ("Select Feiye.feiye_what from Feiye where feiye.feiye_page = ' $pindao '");
$rows = Mysql_fetch_row ($queryr); $rrows = $rows [0];
if (empty ($rrows)) {
mysql_query ("INSERT INTO ' Feiye ' (' feiye_page ', ' feiye_what ') VALUES (' $pindao ', ' $WR ')");
echo "<meta http-equiv= ' refresh ' content= ' 0 ' >";
}else{
if ($WR!= $rrows) {
mysql_query ("Update" Feiye ' Set ' feiye_what ' = ' $wr ' WHERE (' feiye_page ' = ' $pindao '));
echo "<meta http-equiv= ' refresh ' content= ' 0 ' >";
}
}
}
echo "altogether". $total "." Page &nbsp; "." Record "." $sum "." Bar &nbsp; current "." $p "." /"." $total "." Page &nbsp;&nbsp; ";
if ($total = = 1) {
echo "<font class=" page "> Home </font>";
}else{
echo "<a href= ' page=1&menu= $menut ' class=" page "> Home </a>". &nbsp; ";
}
if ($p > 1) {
$prev = $p-1;
echo "<a href= ' page= $prev &menu= $menut ' class= ' page ' > Prev </a> '. ' &nbsp; ";
}else{
echo "<font class=" page > Prev </font> "." &nbsp; ";
}
$page = $_get["page"];
$pagesum = $page +5;
if ($total >= 11) {
if ($pagesum <=11) {
$pagesum = 11;
}
}
if ($pagesum >= $total) {
$pagesum = $total;
}
$pagestart = $page-5;
if ($pagestart <= 0) {
$pagestart = 1;
}
if ($total >= and ($total-4) <= $page) {
$pagestart = $total-10;
}
for ($i = $pagestart; $i <= $pagesum; $i + +) {
if ($i = = $p) {
echo "<font color=cccccc>&nbsp; $i &nbsp;</font>";
}else{
echo "<a href=" page= $i &menu= $menut ' class= ' page ' > $i </a> ';
}
}
if ($p < $total) {
$next = $p + 1;
echo "&nbsp;<a href= ' page= $next &menu= $menut ' class= ' page ' > Next </a> '. ' &nbsp; ";
}else{
echo "<font class=" page > Next </font> "." &nbsp; ";
}
if ($total = = 1) {
echo "<font class=" page "> End </font>";
}else{
echo "<a href= '" page= $total &menu= $menut ' class= ' page ' > Last </a> ';
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.