php 개발 페이지 구현 코드 1/3 페이지
3913 단어 개발 페이지
실행 효과:
conn.php
<?php
$conn = @ mysql_connect("localhost", "root", "") or die(" ");
mysql_select_db("form", $conn);
mysql_query("set names 'GBK'"); // GBK ;
// ,
function htmtocode($content) {
$content = str_replace("
", "<br>", str_replace(" ", " ", $content));
return $content;
}
?>
page.php
1 <?php
2
3 function _PAGEFT($totle, $displaypg = 20, $url = '') {
4
5 global $page, $firstcount, $pagenav, $_SERVER;
6
7 $GLOBALS["displaypg"] = $displaypg;
8
9 if (!$page)
$page = 1;
if (!$url) {
$url = $_SERVER["REQUEST_URI"];
}
//URL :
$parse_url = parse_url($url);
$url_query = $parse_url["query"]; // URL
if ($url_query) {
$url_query = ereg_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); // ,
$page = min($lastpg, $page);
$prepg = $page -1; //
$nextpg = ($page == $lastpg ? 0 : $page +1); //
$firstcount = ($page -1) * $displaypg;
// :
$pagenav = " <B>" . ($totle ? ($firstcount +1) : 0) . "</B>-<B>" . min($firstcount + $displaypg, $totle) . "</B> , $totle ";
// :
if ($lastpg <= 1)
return false;
$pagenav .= " <a href='$url=1'> </a> ";
if ($prepg)
$pagenav .= " <a href='$url=$prepg'> </a> ";
else
$pagenav .= " ";
if ($nextpg)
$pagenav .= " <a href='$url=$nextpg'> </a> ";
else
$pagenav .= " ";
$pagenav .= " <a href='$url=$lastpg'> </a> ";
// , :
$pagenav .= " <select name='topage' size='1' onchange='window.location=\"$url=\"+this.value'>
";
for ($i = 1; $i <= $lastpg; $i++) {
if ($i == $page)
$pagenav .= "<option value='$i' selected>$i</option>
";
else
$pagenav .= "<option value='$i'>$i</option>
";
}
$pagenav .= "</select> , $lastpg ";
}
include("conn.php");
$result=mysql_query("SELECT * FROM `test`");
$total=mysql_num_rows($result);
// pageft(), 10 ( 20 , ), URL( , )。
_PAGEFT($total,5);
echo $pagenav;
$result=mysql_query("SELECT * FROM `test` limit $firstcount,$displaypg ");
while($row=mysql_fetch_array($result)){
echo "<hr><b>".$row[name]." | ".$row[sex];
}
?>
list.php [code] 1 2 3 다음 페이지 전문 을 읽다