本文實(shí)例講述了PHP+MySQL實(shí)現(xiàn)輸入頁碼跳轉(zhuǎn)到指定頁面功能。分享給大家供大家參考,具體如下:
一、代碼
conn.php:
?php
$id=mysql_connect("localhost","root","root")or dir('連接失敗' . mysql_error());
if(mysql_select_db("db_database13",$id))
echo "";
else
echo ('連接失敗' . mysql_error());
mysql_query("set names gb2312");
?>
index.php:
?php session_start();include("conn/conn.php"); if ($_GET['page']=="") {$_GET['page']=1;};?>
html>
head>
meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
title>查詢結(jié)果的分頁顯示/title>
style type="text/css">
!--
.STYLE1 {font-size: 12px}
.STYLE2 {font-size: 13px}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
-->
/style>
/head>
script language="javascript">
function chk(form){
if(form.page.value=0||form.page.value>form.pages.value){
alert("您輸入的頁碼無效!!");
form.page.focus();
return(false);
}
return(true);
}
/script>
body>
table width="500" border="0" cellpadding="0" cellspacing="1" bgcolor="#11DFF0">
tr>
td width="100" height="25" align="center" bgcolor="#11DFF0" class="STYLE2">姓名/td>
td width="100" align="center" bgcolor="#11DFF0" class="STYLE2">編號(hào)/td>
td width="125" align="center" bgcolor="#11DFF0" class="STYLE2">電話/td>
td width="175" align="center" bgcolor="#11DFF0" class="STYLE2">地址/td>
/tr>
?php
if($_GET['page']){
$page_size=3;
$query="select count(*) as total from tb_insert";
$result=mysql_query($query);
$message_count=mysql_result($result,0,"total");
$page_count=ceil($message_count/$page_size);
$offset=($_GET['page']-1)*$page_size;
$query="select * from tb_insert where id order by id desc limit $offset, $page_size";
$result=mysql_query($query);
while ($myrow=@mysql_fetch_array($result)){
?>
tr>
td height="25" align="center" bgcolor="#FFFFFF">span class="STYLE2">?php echo $myrow[name];?>/span>/td>
td align="center" bgcolor="#FFFFFF">span class="STYLE2">?php echo $myrow[number];?>/span>/td>
td align="center" bgcolor="#FFFFFF">span class="STYLE2">?php echo $myrow[tel];?>/span>/td>
td align="center" bgcolor="#FFFFFF">span class="STYLE2">?php echo $myrow[address];?>/span>/td>
/tr>
?php }}?>
/table>
form name="form1" method="get" action="index.php" onSubmit="return chk(this)">
table width="500" border="1" cellpadding="0" cellspacing="0" bgcolor="#11DFF0">
tr>
td width="42%" align="center" valign="middle">span class="STYLE1">nbsp;nbsp;頁次:?php echo $_GET['page'];?>
/ ?php echo $page_count;?> 頁 記錄:?php echo $message_count;?> 條 /span>/td>
td width="58%" height="28" align="left" valign="middle">span class="STYLE1"> nbsp;分頁:
?php
if($_GET['page']!=1)
{
echo "a href=index.php?page=1>首頁/a>nbsp;";
echo "a href=index.php?page=".($_GET['page']-1).">上一頁/a>nbsp;";
}
if($_GET['page']$page_count)
{
echo "a href=index.php?page=".($_GET['page']+1).">下一頁/a>nbsp;";
echo "a href=index.php?page=".$page_count.">尾頁/a>";
if($_GET['page']= $page_count and $_GET['page']>0)
{
echo "a href=index.php?page=".$_GET['page'].">/a>";
}
}
?>
input name="page" type="text" size="3">
input type="hidden" name="pages" value="?php echo $page_count;?>">
input type="submit" name="Submit" value="跳轉(zhuǎn)">
/span> /td>
/tr>
/table>
/form>
/body>
/html>
二、運(yùn)行結(jié)果
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php+mysql數(shù)據(jù)庫操作入門教程》、《php+mysqli數(shù)據(jù)庫程序設(shè)計(jì)技巧總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。
您可能感興趣的文章:- php+mysql分頁代碼詳解
- mysql+php分頁類(已測(cè))
- php5 mysql分頁實(shí)例代碼
- php mysql數(shù)據(jù)庫操作分頁類
- PHP使用Mysqli類庫實(shí)現(xiàn)完美分頁效果的方法
- PHP+Mysql+Ajax實(shí)現(xiàn)淘寶客服或阿里旺旺聊天功能(前臺(tái)頁面)
- php分頁查詢mysql結(jié)果的base64處理方法示例
- PHP頁面輸出搜索后跳轉(zhuǎn)下一頁的處理方法
- PHP翻頁跳轉(zhuǎn)功能實(shí)現(xiàn)方法
- php顯示頁碼分頁類的封裝
- php頁碼形式分頁函數(shù)支持靜態(tài)化地址及ajax分頁