/mysql Tutorial pagination Class (with pagination feature)
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;
}
}
}
Return to pagination 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 " ";
}else{
if ($wr! = $rrows) {
mysql_query ("Update ' Feiye ' set ' feiye_what ' = ' $wr ' WHERE (' feiye_page ' = ' $pindao ')");
echo " ";
}
}
}
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 " ";
}else{
if ($wr! = $rrows) {
mysql_query ("Update ' Feiye ' set ' feiye_what ' = ' $wr ' WHERE (' feiye_page ' = ' $pindao ')");
echo " ";
}
}
}
echo "Total". " $total "." Page "." Record "." $sum "." Bar current "." $p "." /"." $total "." Page ";
if ($total = = 1) {
echo "Home";
}else{
echo "Home". " ";
}
if ($p > 1) {
$prev = $p-1;
echo "prev". " ";
}else{
echo "prev". " ";
}
$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 "$i";
}else{
echo "$i";
}
}
if ($p < $total) {
$next = $p + 1;
echo "Next page". " ";
}else{
echo "Next page". " ";
}
if ($total = = 1) {
echo "Last";
}else{
echo "Last";
}
}
http://www.bkjia.com/PHPjc/630812.html www.bkjia.com true http://www.bkjia.com/PHPjc/630812.html techarticle /mysql Tutorial Pagination class (with pagination function) function fenyezhixin ($table, $pagesize =, $paixu =, $do =, $wwhere =) {if ($table = = News_fabu) or ($ Table = = Product_fabu) or ($table = = mes ...