Recently, Mo Fangshu's website created a page with all comments and directly called some fields in the wp database. This is not difficult. For me, a newbie who just learned PHP, the most difficult thing is the paging function. At the beginning, I used the most Basic paging code is implemented, but the code and experience are very poor. It only realizes page turning up and down. Later I found this function, which is not bad. I would like to share it: Create a mypage.php file and load it later.
if(!function_exists("pageDivide")){
#$total total information
#$shownu display quantity, default 20
#$url link to this page
function pageDivide($total,$ shownu=20,$url=''){
#$page current page number
#$sqlfirst mysql database starting item
#$pagecon paging navigation content
global $page,$sqlfirst,$pagecon,$_SERVER;
$GLOBALS ["shownu"]=$shownu;
if(isset($_GET['page'])){
$page=$_GET['page'];
}else $page=1;
#if$ The url uses the default value, which is a null value, and the value is assigned to the URL of this page
if(!$url){ $url=$_SERVER["REQUEST_URI"];}
#URL analysis
$parse_url=parse_url($url);
@$url_query=$parse_url["query"]; //Get the content after the question mark?
if($nextpg) $pagecon .=" Next page "; else $pagecon .=" Next page";
if($page!=$lastpg) $pagecon.=" Last page "; else $pagecon .=" Last page";
# Drop down jump list, loop through all page numbers
$pagecon .="Go to
for($i=1;$i<=$lastpg;$i++){
if( $i==$page) $pagecon .="n";
else $pagecon .="n";
}
$pagecon .=" page, total $lastpg page";
}
}else die('pageDivide() function with the same name already exists!');
?>
Copy code
require_once('mypage.php');
$result=mysql_query("select * from table", $myconn);
$total=mysql_num_rows($result); //Get the total number of information
pageDivide($total,10); //Call the paging function, parameter two is the number of items displayed on each page
//Database operation, select the data of your own database, this is just an example, the database link is closed, there is no operation here Explained.
$result=mysql_query("select * from table limit $sqlfirst,$shownu", $myconn);
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn