티스토리 뷰
[ JavaScript ][ JS ] pageNevi(nowPage, totalNum, pLimit, bLimit);
MiniNeko 2015. 11. 29. 05:04// pageNevi
var returnStr = "";
var nowPage = 1;
var nowPageShare = 0;
var totalNum = 0;
var maxPage = 0;
var pLimit = 10;
var bLimit = 10;
var totalPage = 0;
var bTotalPage = 0;
var prevLabel = "<img src=`/login@admin/_img/pageNevi/btnPrev.gif` />";
var prevOnLabel = "<img src=`/login@admin/_img/pageNevi/btnPrev_on.gif` style=`cursor:hand; border:none;` />";
var nextLabel = "<img src=`/login@admin/_img/pageNevi/btnNext.gif` />";
var nextOnLabel = "<img src=`/login@admin/_img/pageNevi/btnNext_on.gif` style=`cursor:hand; border:none;` />";
var startLabel = "<img src=`/login@admin/_img/pageNevi/btnStart.gif` />";
var startOnLabel = "<img src=`/login@admin/_img/pageNevi/btnStart_on.gif` style=`cursor:hand; border:none;` />";
var endLabel = "<img src=`/login@admin/_img/pageNevi/btnEnd.gif` />";
var endOnLabel = "<img src=`/login@admin/_img/pageNevi/btnEnd_on.gif` style=`cursor:hand; border:none;` />";
var formAction = "/html/04_shop/shop_01.php";
var param = "";
function pageNevi(nowPage, totalNum, pLimit, bLimit) {
this.nowPage = nowPage;
this.nowPageShare = (Math.ceil(nowPage/bLimit) - 1) * bLimit;
this.totalNum = totalNum;
this.pLimit = pLimit;
this.bLimit = bLimit;
this.totalPage = Math.ceil(totalNum / pLimit);
this.bTotalPage = Math.ceil(totalPage / bLimit);
if(Math.ceil(totalPage/bLimit) == Math.ceil(nowPage/bLimit)) {
this.maxPage = totalPage % bLimit;
if(this.maxPage==0) { this.maxPage=10; }
} else {
this.maxPage = bLimit;
}
startPageHandler();
prevPageHandler();
neviPageHandler();
nextPageHandler();
endPageHandler();
return returnStr;
}
function neviPageHandler() {
for(i=1; i <= maxPage; i++) {
if(nowPage == (i+nowPageShare)) {
returnStr += "<td style=`width:10px; aling:center`><strong>"+(i+nowPageShare)+"</strong></td>";
} else {
returnStr += "<td style=`width:10px; aling:center`><a href=`"+formAction+"?nowPage="+(i+nowPageShare)+"` onFocus=`this.blur()`>"+(i+nowPageShare)+"</a></td>";
}
}
}
function startPageHandler() {
returnStr += "<table><tr>";
if(0 != (Math.ceil(nowPage/bLimit)-1)) {
returnStr += "<td><a href=`"+formAction+"?nowPage="+((Math.ceil(nowPage/bLimit)-1)*bLimit)+"` onFocus=`this.blur()`>" + startOnLabel + "</a></td>";
} else {
returnStr += "<td>" + startLabel + "</td>";
}
}
function prevPageHandler() {
if(nowPage != 1) {
returnStr += "<td style=`padding-right:10px;`><a href=`"+formAction+"?nowPage="+(nowPage-1)+"` onFocus=`this.blur()`>"+prevOnLabel+"</a></td>";
} else {
returnStr += "<td style=`padding-right:10px;`>"+prevLabel+"</td>";
}
}
function nextPageHandler() {
if(nowPage != totalPage) {
returnStr += "<td style=`padding-left:10px;`><a href=`"+formAction+"?nowPage="+(nowPage+1)+"` onFocus=`this.blur()`>"+nextOnLabel+"</a></td>";
} else {
returnStr += "<td style=`padding-left:10px;`>" + nextLabel + "</td>";
}
}
function endPageHandler() {
if(Math.ceil(totalPage/bLimit) > Math.ceil(nowPage/bLimit)) {
returnStr += "<td><a href=`"+formAction+"?nowPage="+(Math.ceil(nowPage/bLimit)*bLimit+1)+"` onFocus=`this.blur()`>" + endOnLabel + "</a></td>";
} else {
returnStr += "<td>" + endLabel + "</td>";
}
returnStr += "</tr></table>";
}
---------------------------------------------------------------------------------------------------------------------------
// HTML
< SCRIPT language="javascript" type="text/javascript" src="/login@admin/_js/pageNevi.js" />
< !-- PageNavi START -->
< tr>
<td height="50" colspan="5" align="center"><span class="bbs3"><SCRIPT>document.write(pageNevi(<?=$nowPage?>,<?=$totalNum?>,<?=$pLimit?>,<?=$bLimit?>))</SCRIPT></td>
< /tr>
< !-- PageNavi END -->
---------------------------------------------------------------------------------------------------------------------------
< ?
$pLimit = 9;
$bLimit = 10;
$nowPage = $_REQUEST["nowPage"];
if($nowPage == "") {
$nowPage = 1;
}
$query="SELECT * FROM product ORDER BY idx DESC LIMIT ".(($nowPage-1)*$pLimit).", ".$pLimit;
$result=mysql_query($query);
$dataNum = mysql_affected_rows();
$rowData=mysql_fetch_array($result);
?>
'Language > JavaScript_JS' 카테고리의 다른 글
[ JavaScript_JS ] slidesjs 슬라이드 효과 (0) | 2021.01.20 |
---|---|
[ JavaScript_JS ] marquee - text 문자 롤링 (0) | 2015.11.29 |
[ JavaScript ][ JS ] 도메인, 현재페이지 경로 구하기 / domain URL location href (0) | 2015.11.29 |
[ JavaScript ][ JS ] mTree (0) | 2015.11.29 |
[ JavaScript ][ JS ] keyEvent // enterEvent (0) | 2015.11.29 |