Questions about the PHP paging display

Source: Internet
Author: User
I am listening to the introduction of the principle of paging in PHP100 video. According to the code provided, after running the discovery page is not able to proceed, the URL has been displayed? Page=2page=3page=4, and so on, just started to find the reason is because the ereg_replace function has been in the 5.3 version of the use, instead of preg_replace or not, please trouble Master to give answers. Thank you.

Code:

function _pageft ($totle, $displaypg = A, $url = ") {
Global $page, $firstcount, $pagenav, $_server;
$GLOBALS ["displaypg"] = $DISPLAYPG;
if (! $page)
$page = 1;
if (! $url) {
$url = $_server["Request_uri"];
}
URL Analysis:
$parse _url = Parse_url ($url);
$url _query = $parse _url["Query"]; Query string to take out the URL separately
if ($url _query) {
$url _query = Preg_replace ("/(^|&) page= $page/", "", $url _query);

$url = Str_replace ($parse _url["Query"], $url _query, $url);
if ($url _query)
$url. = "&page";
Else
$url. = "page";
} else {
$url. = "? page";
}
$LASTPG = Ceil ($totle/$DISPLAYPG); Last page, also the total number of pages
$page = min ($lastpg, $page);
$PREPG = $page-1; Previous page
$NEXTPG = ($page = = $lastpg? 0: $page + 1); Next page
$firstcount = ($page-1) * $DISPLAYPG;
Start Page navigation bar code:
$pagenav = "Show " . ($totle? ($firstcount + 1): 0). "- " . Min ($firstcount + $DISPLAYPG, $totle). "Records, a total of $totle records ";
If only one page jumps out of the function:
if ($LASTPG <= 1)
return false;
$pagenav. = "Home";
if ($PREPG)
$pagenav. = "front page";
Else
$pagenav. = "front page";
if ($NEXTPG)
$pagenav. = "Back Page";
Else
$pagenav. = "Back Page";
$pagenav. = "Last";
Drop-down Jump List, looping through all page numbers:
$pagenav. = "To \ n "; for ($i = 1; $i <= $lastpg; $i + +) {if ($i = = $page) $pagenav. = "$i \ n "; else $pagenav. = "$i \ n "; } $pagenav. = "Page, total $lastpg page ";
}
Include ("conn.php");
$result =mysql_query ("select * from ' p_newsbase '");
$total =mysql_num_rows ($result);
Call Pageft (), displaying 10 messages per page (this parameter can be omitted using the default 20 o'clock), using the page URL (default, so omitted).
_pageft ($total, 1);
Echo $pagenav;
$result =mysql_query ("select * from ' p_newsbase ' limit $firstcount, $displaypg");
while ($row =mysql_fetch_array ($result)) {
echo " ". $row [' author ']." | ". $row [' title '];
}

?


Reply to discussion (solution)

then you have to take a look at the php100 video.

1, function _pageft the last line to add return $pagenav;
2. Write this when calling

 $page = isset ($_get[' page ')? $_get[' page ': 1;echo _pageft (100);//The total number of records you intend to process 

Do not database can also be tested

thank moderators, the problem solved, the main is not in-depth of their own study, thank you moderator, feel the concern of the Organization, hehe, thank you! More advice is needed in the future!

  • 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.