테이블에 대한 사항은 별도로 table-01.php 파일로 분리했다.
코드가 너무 복잡해 보이는 경향을 줄이기 위함이다.
=== index.php ===
<?php
require_once 'dbconnect.php'; // db접속 성공
require_once 'phpclass/dbClass.php';
require_once 'phpclass/boardiClass.php';
$c = new MySQLiDbClass();
$link_url = $_SERVER['PHP_SELF']; // 현재 실행중인 파일명 가져오기
$rowsPage = 12;
// 화면에 출력할 칼럼 발췌
$flddata ="uid,ItemName,Price,Quantity";
$where ="";
$curPage = isset($_GET['p']) ? $_GET['p'] : 1;
$result = $c->getDbArray('items',$where,$flddata,'',$rowsPage,$curPage);
$totalcnt = $c->getDbRows('items',$where);
$b = new boardiClass();
?>
<!DOCTYPE html>
<head>
<meta charset="UTF-8" />
<meta name="robots" content="noindex,nofollow"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no"/>
<meta http-equiv="X-UA Compatible" control="IE=edge,chrome=1" />
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" href="css/table.css" />
<script src="http://code.jquery.com/jquery.min.js" ></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/display.js"></script>
</head>
<body>
<main class="container-fluid">
<div class="container">
<div class="col-md-2 sidebar">
<div class="row">
<!-- 사이드 메뉴 영역 -->
</div>
</div>
<!-- Main 화면 -->
<div class="col-md-10 content">
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-body">
<?php require_once 'table-01.php';?>
</div>
</div>
</div>
</div>
</div>
</div>
</main>
</body>
</html>
=== table-01.php ===
<table class="table table-hover">
<thead>
<tr>
<th class="header" width="30"><input type="checkbox" id="checkall" /></th>
<th class="header" width="100">No</th>
<th class="header" width="250">아이템</th>
<th class="header" width="250">가격</th>
<th class="header" width="200">수량</th>
</tr>
</thead>
<tbody>
<?php
// 테이블 리스트
$b->tablelistView_checkbox($result);
?>
</tbody>
<td colspan="5" style="text-align:left;">
<button type="button" class="btn btn-success btn-sm" id="optdel">선택삭제</button>
<button type="button" class="btn btn-success btn-sm" id="optmp3">선택듣기</button>
</td>
</table>
<a class="btn btn-default pull-right">글쓰기</a>
<?php $b->PageLinkView($link_url,$totalcnt,$rowsPage,$curPage);?>
// column 개수, 게시물 총개수 만큼 자동으로 화면 출력 function tablelistView_checkbox($result){ global $dbconn; while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { $view='<tr class="tr1">'; foreach($row as $column => $value) { if($column== 'uid'){ $view.='<td><input type="checkbox" class="chkbox" name="uid[]" value="'.$value.'" /></td>'; } $view.='<td class="td2">'.$value.'</td>'; } $view.='</tr>'; echo $view; } }
|
function PageLinkView($link_url,$totalcnt,$rowsPage,$curPage,$m){ echo '<div style="position:relative;vertical-align:top;padding-top:0;margin-top:0">'; echo "<span style='position:absolute;top:10px;'>[전체 글수:".$totalcnt."]</span>"; echo '<div class="text-center">'; echo '<ul class="pagination">'; $Info = $this->PageList($totalcnt,$rowsPage,$curPage,''); if($Info['current_block'] > 2){ echo "<li><a href='".$link_url."?m=$m&p=1'>◀</a></li> "; } if($Info['current_block'] > 1){ echo "<li><a href='".$link_url."?m=$m&p=".$Info['prev']."'>◁</a></li> "; } foreach($Info['current'] as $w) { if($curPage == $w){ echo "<li><a href='".$link_url."?m=$m&p=".$w."'><span style='color:red;'>".$w."</span></a></li> "; } else { echo "<li><a href='".$link_url."?m=$m&p=".$w."'>".$w."</a></li> "; } } if($Info['current_block'] < ($Info['total_block'])){ echo "<li><a href='".$link_url."?m=$m&p=".$Info['next']."'>▷</a></li> "; } if($Info['current_block'] < ($Info['total_block']-1)){ echo "<li><a href='".$link_url."?m=$m&p=".$Info['totalPage']."'>▶</a></li> "; } echo '</ul>'; echo '</div>'; echo '</div>'; } |
// $curPage : 현재 페이지, $totalcnt : 총 게시물수 // $block_limit : 한 화면에 뿌려질 게시글 개수 function PageList($totalcnt,$rowsPage,$curPage,$block_limit) { $block_limit = $block_limit ? $block_limit : 10; // 한 화면에 보여줄 개수 기본 10으로 설정
// 총 페이지수 구하기 $totalPage = ceil($totalcnt/$rowsPage); if($totalPage == 0) { ++$totalPage; } $total_block = ceil($totalPage / $block_limit); //전체 블록 갯수
$curPage = $curPage ? $curPage : 1; // 현재 페이지
// 현재 블럭 : 화면에 표시될 페이지 리스트 $current_block=ceil($curPage/$block_limit); // 현재 블럭에서 시작페이지 $fstPage = (((ceil($curPage/$block_limit)-1)*$block_limit)+1); // 현재 블럭에서 마지막 페이지 $endPage = $fstPage + $block_limit -1; if($totalPage < $endPage) { $endPage = $totalPage; }
// 시작 바로 전 페이지 $prev_page = $fstPage - 1; // 마지막 다음 페이지 $next_page = $endPage + 1;
foreach(range($fstPage, $endPage) as $val) { $row[] = $val; } // 배열로 결과를 돌려준다. return array( 'total_block' => $total_block, 'current_block' => $current_block, 'totalPage' => $totalPage, 'fstPage' => $fstPage, 'endPage' => $endPage, 'prev' => $prev_page, 'next' => $next_page, 'current' => $row ); }
|