[PHP] 페이징(페이지 리스트) 구현 (2007/12/15 수정)
로빈아빠
본문
원본작성 : 현태풍 님
원본출처 : http://www.phpschool.com/gnuboard4/bbs/board.php?bo_table=tipntech&wr_id=47680&page=1
<?
$mysql_host = "localhost";
$mysql_user = "아이디";
$mysql_password = "비밀번호";
$dmysql_db = "디비네임";
$dbconn = mysql_connect("$mysql_host","$mysql_user","$mysql_password") or die("데이터베이스 연결에 실패하였습니다.");
mysql_select_db($mysql_db, $dbconn);
$page_sql=mysql_query("select no from 테이블이름 order by no desc");
$tot=mysql_num_rows($page_sql);
$pagemax=10; // 한페이지에 몇개씩 보여줄까요.
$page_scale=5; // 하단 페이지 색인갯수
$page_tot=(int)($tot/$pagemax);
if($page_tot<($tot/$pagemax)) {
$page_tot = $page_tot+1;
}
if(!$page_num) {
$page_num=1;
$start_line=0;
}
else {
$start_line=($pagemax * $page_num)-$pagemax;
}
$sql=mysql_query("select * from 테이블이름 order by no desc limit $start_line,$pagemax");
?>
전체글 : 총<font color='#ff3333'><?=$tot?></font>건 (현재/전체 :<font color='#CC0033'><?=$page_num,"</font>/<font color='#CC0033'>",$page_tot?></font>page)
<table border="0" cellpadding="0" cellspacing=0">
<?
while ($data=mysql_fetch_array($sql)) {
?>
<tr>
<td>반복적으로 보여줄 내용</td>
</tr>
<?
}
?>
</table>
<span align="center"><?
//본문밑에 페이지보이실부분..
$blockpage=(int)(($page_num-1)/$page_scale)*$page_scale+1;
if($blockpage==1) {
echo"[ ";
}
else {
$page=$blockpage-$page_scale;
echo "<a href='파일이름.php?page_num=0'>[처음]</a> <a href='파일이름.php?page_num=$page'>[이전 ${page_scale}개]</a> [ ";
}
$i=1;
while($i<=$page_scale&&$blockpage<=$page_tot) {
if($page_num==$blockpage) {
?>
<b><u><font color='#bb0000'><? echo "$blockpage" ?></font></u></b>
<?
}
else {
echo " <a href='파일이름.php?page_num=$blockpage'>$blockpage</a> ";
}
$blockpage=$blockpage+1;
$i++;
}
if($blockpage>$page_tot) {
echo"] ";
}
else {
$page=$blockpage-$page_scale;
echo "] <a href='파일이름.php?page_num=$blockpage'>[다음 ${page_scale}개]</a> <a href='파일이름.php?page_num=$page_tot'>[끝]</a>";
}
?></span>
<?
echo mysql_error();
mysql_close($dbconn); // MySQL에 접속종료
?>
원본출처 : http://www.phpschool.com/gnuboard4/bbs/board.php?bo_table=tipntech&wr_id=47680&page=1
<?
$mysql_host = "localhost";
$mysql_user = "아이디";
$mysql_password = "비밀번호";
$dmysql_db = "디비네임";
$dbconn = mysql_connect("$mysql_host","$mysql_user","$mysql_password") or die("데이터베이스 연결에 실패하였습니다.");
mysql_select_db($mysql_db, $dbconn);
$page_sql=mysql_query("select no from 테이블이름 order by no desc");
$tot=mysql_num_rows($page_sql);
$pagemax=10; // 한페이지에 몇개씩 보여줄까요.
$page_scale=5; // 하단 페이지 색인갯수
$page_tot=(int)($tot/$pagemax);
if($page_tot<($tot/$pagemax)) {
$page_tot = $page_tot+1;
}
if(!$page_num) {
$page_num=1;
$start_line=0;
}
else {
$start_line=($pagemax * $page_num)-$pagemax;
}
$sql=mysql_query("select * from 테이블이름 order by no desc limit $start_line,$pagemax");
?>
전체글 : 총<font color='#ff3333'><?=$tot?></font>건 (현재/전체 :<font color='#CC0033'><?=$page_num,"</font>/<font color='#CC0033'>",$page_tot?></font>page)
<table border="0" cellpadding="0" cellspacing=0">
<?
while ($data=mysql_fetch_array($sql)) {
?>
<tr>
<td>반복적으로 보여줄 내용</td>
</tr>
<?
}
?>
</table>
<span align="center"><?
//본문밑에 페이지보이실부분..
$blockpage=(int)(($page_num-1)/$page_scale)*$page_scale+1;
if($blockpage==1) {
echo"[ ";
}
else {
$page=$blockpage-$page_scale;
echo "<a href='파일이름.php?page_num=0'>[처음]</a> <a href='파일이름.php?page_num=$page'>[이전 ${page_scale}개]</a> [ ";
}
$i=1;
while($i<=$page_scale&&$blockpage<=$page_tot) {
if($page_num==$blockpage) {
?>
<b><u><font color='#bb0000'><? echo "$blockpage" ?></font></u></b>
<?
}
else {
echo " <a href='파일이름.php?page_num=$blockpage'>$blockpage</a> ";
}
$blockpage=$blockpage+1;
$i++;
}
if($blockpage>$page_tot) {
echo"] ";
}
else {
$page=$blockpage-$page_scale;
echo "] <a href='파일이름.php?page_num=$blockpage'>[다음 ${page_scale}개]</a> <a href='파일이름.php?page_num=$page_tot'>[끝]</a>";
}
?></span>
<?
echo mysql_error();
mysql_close($dbconn); // MySQL에 접속종료
?>
관련링크
댓글목록
등록된 댓글이 없습니다.