課程
/后端開發(fā)
/PHP
/PHP+MySQL分頁(yè)原理實(shí)現(xiàn)
麻煩老師提供下課件源碼下載
2019-04-25
源自:PHP+MySQL分頁(yè)原理實(shí)現(xiàn) 5-1
正在回答
<html> <head> ????<meta?http-equiv="Content-Type"?content="text/html;charset=utf-8"> </head> <body> <?php /** ?*?Created?by?PhpStorm. ?*?User:?123 ?*?Date:?2020/2/14 ?*?Time:?12:16 ?*/ /*1.傳入頁(yè)碼*/ $page?=?$_GET['p']; /*2.根據(jù)頁(yè)碼取出數(shù)據(jù),?php?->?mysql*/ $host?=?"localhost"; $username?=?"root"; $password?=?"123456"; $db?=?"page"; $pageSize?=?3; $showPage?=?5; //連接數(shù)據(jù)庫(kù) $conn?=?mysqli_connect($host,?$username,?$password,?$db); if?(!$conn)?{ ????var_dump("連接失敗"); } //設(shè)置數(shù)據(jù)庫(kù)的編碼格式,防止亂碼 mysqli_query($conn,?"SET?NAMES?UTF8"); //編寫sql獲取分頁(yè)數(shù)據(jù)?SELECT?*?FROM?表名?LIMIT?起始位置,顯示條數(shù) $sql?=?"SELECT?*?FROM?test?LIMIT?"?.?($page?-?1)?*?$pageSize?.?",{$pageSize}"; //把sql語(yǔ)句傳送數(shù)據(jù)中 $result?=?mysqli_query($conn,?$sql); //處理數(shù)據(jù) echo?"<table?border='1'?cellspacing='0'?width='40%'?class='margin:?0?auto'>"; echo?"<tr><td>ID</td><td>name</td></tr>"; while?($row?=?mysqli_fetch_assoc($result))?{ ????echo?"<tr><td>{$row['id']}</td><td>{$row['name']}</td></tr>"; } echo?"</table>"; //釋放結(jié)果,關(guān)閉連接 mysqli_free_result($result); //獲取數(shù)據(jù)總數(shù) $total_sql?=?"SELECT?COUNT(*)?FROM?test"; $total_result?=?mysqli_fetch_assoc(mysqli_query($conn,?$total_sql)); $total?=?$total_result['COUNT(*)']; $total_page?=?ceil($total?/?$pageSize); mysqli_close($conn); //3.顯示數(shù)據(jù)?+?分頁(yè)條 $page_banner?=?''; if?($page?>?1)?{ ????$page_banner?.=?"<a?href='"?.?"{$_SERVER['PHP_SELF']}?p=1"?.?"'>首頁(yè)</a>"; ????$page_banner?.=?"<a?href='"?.?"{$_SERVER['PHP_SELF']}?p="?.?($page?-?1)?.?"'>上一頁(yè)</a>"; } //初始化數(shù)據(jù) $start?=?1;?//開始頁(yè)面 $end?=?$total_page;?//結(jié)束頁(yè)面 $pageOffset?=?($showPage?-?1)?/?2; if?($total_page?>?$showPage)?{??//如果總頁(yè)面大于顯示的頁(yè)面 ????if?($page?>?$pageOffset?+?1)?{?//如果當(dāng)前頁(yè)面大于偏移量 ????????$page_banner?.=?"..."; ????} ????if?($page?>?$pageOffset)?{?//當(dāng)前頁(yè)大于偏移量 ????????$start?=?$page?-?$pageOffset; ????????$end?=?$total_page?>?$page?+?$pageOffset???$page?+?$pageOffset?:?$total_page; ????}?else?{ ????????$start?=?1; ????????$end?=?$total_page?>?$showPage???$showPage?:?$total_page; ????} ????if?($page?+?$pageOffset?>?$total_page)?{ ????????$start?=?$start?-?($page?+?$pageOffset?-?$end); ????} } for?($i?=?$start;?$i?<=?$end;?$i++)?{ ????$page_banner?.=?"<a?href='"?.?"{$_SERVER['PHP_SELF']}?p={$i}"?.?"'>{$i}</a>"; } //尾部省略 if?($total_page?>?$showPage?&&?$total_page?>?$page?+?$pageOffset){ ????$page_banner?.=?"..."; } if?($page?<?$total_page)?{ ????$page_banner?.=?"<a?href='"?.?"{$_SERVER['PHP_SELF']}?p="?.?($page?+?1)?.?"'>下一頁(yè)</a>"; ????$page_banner?.=?"<a?href='"?.?"{$_SERVER['PHP_SELF']}?p={$total_page}"?.?"'>尾頁(yè)</a>"; } $page_banner?.=?"總頁(yè)數(shù){$total_page},"; $page_banner?.=?"<form?action='demo1.php'?method='get'>"; $page_banner?.=?"到第<input?type='text'?size='2'?name='p'>頁(yè)"; $page_banner?.=?"<input?type='submit'?value='確定'>"; $page_banner?.=?"</form>"; echo?$page_banner; ?> </body> </html>
跟敲,數(shù)據(jù)庫(kù)表名自行修改,如遇到問題請(qǐng)指正
<html><head>????<meta?http-equiv="Content-type"?content="text/html;?charset=utf-8"?></head><style>????body{????????font-size:12px;????????FONT-FAMILY:verdana;????????width:100%;????}????div.page{????????text-align:certer;????}????div.content{????????height:300px;????}????div.page?a{????????border:#aaaaddd?1px?solid;????????text-decoration:none;????????padding:2px?5px?2px?5px;????????margin:2px;????}????div.page?span.current?{????????border:#000099?1px?solid;????????background-color:#000099;????????padding:4px?6px?4px?6px;????????margin:2px;????????color:#fff;????????font-weight:bold;????}????div.page?span.disable{????????border:#eee?1px?solid;????????padding:2px?5px?2px?5px;????????margin:2px;????????color:#ddd;????}????div.page?form{????????display:inline;????}</style><body><?php????//傳入頁(yè)碼????$page?=?$_GET['p'];????//根據(jù)頁(yè)碼取出數(shù)據(jù):php->mysql處理????$host?=?"localhost";????$username?=?"root";????$password?=?"root";????$db?=?"名字"????$pageSize?=?10;????$showPage?=?5;????//鏈接數(shù)據(jù)庫(kù)????$conn=mysql_connect($host,$username,$password);????if(!$conn){????????echo?"數(shù)據(jù)庫(kù)連接失敗";????????exit;????}????//選擇所要操作的數(shù)據(jù)庫(kù)????mysql_select_db($db);????//設(shè)置數(shù)據(jù)庫(kù)編碼格式????mysql_query("SET?NAMES?UTF8");????//編寫sql獲取分頁(yè)(拼接用.)數(shù)據(jù)SELECT?*?FROM?表明?LIMIT?起始位置,顯示條數(shù)????$sql?=?"SELECT?*?FROM?page?LIMIT"?.($page-1)*$pageSize?.",?{$pageSize}";????//把sql語(yǔ)句傳送數(shù)據(jù)庫(kù)????$result?=?mysql_query($sql);????//處理數(shù)據(jù)源$result????echo?"<div?class='content'>";????echo?"<table?border=1?cellspace=0?width=40%?align='center'>";????echo?"<tr><td>ID</td><td>NAME</td></tr>";????while($row?=?mysql_fetch_assoc($result)){????????echo?"<tr>";????????echo?"<td>{$row['id']}</td>";????????echo?"<td>{$row['name']}</td>";????????echo?"</tr>";????}????echo?"</table></div>";????//釋放結(jié)果,關(guān)閉鏈接????mysql_free_result($result);????//獲取數(shù)據(jù)總數(shù)????$total_sql?=?"SELECT?COUNT(*)?FROM?表名";????$total_result?=?mysql_fetch_array(mysql_query($total_sql));????$total?=?$total_result[0];????//計(jì)算頁(yè)數(shù)????$total_pages?=?ceil($total/$pageSize);????mysql_close($conn);????//顯示數(shù)據(jù)+分頁(yè)條????$page_banner?=?"<div?class='page'>";????//計(jì)算偏移量????$pageoffset?=?($showPage-1)/2;????if($page?>?1){????????$page_banner?.=?"<a?href='"?.$_SERVER['PHP_SELF'].?"?p=1'><<首頁(yè)</a>";????????$page_banner?.=?"<a?href='"?.$_SERVER['PHP_SELF'].?"?p="?.($page-1).?"'><上一頁(yè)</a>";????}else{????????$page_banner?.=?"<span?class='disable'><<首頁(yè)</a></span>";????????$page_banner?.=?"<span?class='disable'><上一頁(yè)</a></span>";????}????//初始化數(shù)據(jù)????$start?=?1;????$end?=?$total_pages;????if($total_pages?>?$showPage){????????if($page?>?$pageoffset?+?1){????????????$page_banner?.=?"...";????????}????????if($page?>?$pageoffset){????????????$start?=?$page?-?$pageoffset;????????????$end?=?$total_pages?>?$page+$pageoffset???$page+$pageoffset?:?$total_pages;????????}else{????????????$start?=?1;????????????$end?=?$total_pages?>?$showPage???$showPage?:?$total_pages;????????}????????if($page?+?$pageoffset?>?$total_pages){????????????$start?=?$start?-?($page?+?$pageoffset?-?$end);????????}????}????for($i?=?$start;$i<=$end;$i++){????????if($page?==?$i){????????????$page_banner?.=?"<span?class='current'>{$i}</span>";????????}else{????????????$page_banner?.=?"<a?href='"?.$_SERVER['PHP_SELF'].?"?p="?.$i.?"'>{$i}</a>";????????}????}????//尾部省略????if($total_pages?>?$showPage?&&?$total_pages?>?$page?+?$pageoffset){????????$page_banner?.="...";????}????if($page?<?$total_pages){????????$page_banner?.=?"<a?href='"?.$_SERVER['PHP_SELF'].?"?p="?.($page+1).?"'>下一頁(yè)></a>";????????$page_banner?.=?"<a?href='"?.$_SERVER['PHP_SELF'].?"?p=".($total_pages)"'>尾頁(yè)>></a>";????}else{????????$page_banner?.=?"<span?class='disable'>下一頁(yè)></a></span>";????????$page_banner?.=?"<span?class='disable'>尾頁(yè)>></a></span>";????}????????$page_banner?.=?"共{$total_pages}頁(yè),";????$page_banner?.=?"<form?action='fenye.php'?method='get'>";????$page_banner?.=?"到第<input?type='text'?size='2'?name='p'>頁(yè)";????$page_banner?.=?"<imput?type='submit'?value='確定'";????$page_banner?.=?"</form></div>";????echo?$page_banner;?></body></html>
舉報(bào)
引導(dǎo)大家完成一個(gè)PHP+MySQL分頁(yè)功能,由簡(jiǎn)入繁的剖析原理
1 回答為什么沒有提供下載?
3 回答為什么不提供下載呢?
3 回答源代碼在哪里下載呢
1 回答老師可以把源碼公開一下嗎,謝謝!!!
2 回答請(qǐng)問老師您的代碼不能下載嗎?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2020-02-14
2020-02-14
跟敲,數(shù)據(jù)庫(kù)表名自行修改,如遇到問題請(qǐng)指正