수업내용
페이지 사이즈
페이지 List 사이즈
전체 레코드
총 페이지 수
현재 레코드
현재 페이지
하단 가로 시작 : 1번
하단 가로 마지막 : 10번
<? include $_SERVER["DOCUMENT_ROOT"]."/include/top0403.php" ?>
<? include $_SERVER["DOCUMENT_ROOT"]."/include/dbconn0403.php" ?>
<style>
/* 테이블 규격 및 정렬 수정 */
#tb{
width:600px;
text-align:center;
font-size:21px;
}
/* 방문 전 링크 밑줄 제거 */
section a:link{
text-decoration:none;
}
/* 방문 후 링크 밑줄 제거 */
section a:visited{
text-decoration:none;
}
/* 마우스 커서 적용 시 밑줄 표시 */
section a:hover{
text-decoration:underline;
}
/* 클릭 시 밑줄 표시 */
section a:active{
text-decoration:underline;
}
</style>
<?php
// 검색 값 불러오기
$ch1 = $_REQUEST['ch1'];
$ch2 = $_REQUEST['ch2'];
// 페이지 사이즈
$pageSize = 10;
// 페이지 리스트 사이즈(한페이지 범위)
$pageListSize = 10;
if ($_REQUEST['idx']==''){
$idx = 0;
}else{
$idx=$_REQUEST['idx'];
}
// 검색 쿼리문
if($ch1=='' || $ch2==''){
$SQL="select * from member0403 order by idx desc limit $idx, $pageSize ";
$count="select count(*) tc from member0403 ";
}else if($ch1=='name'){
$SQL="select * from member0403 where name like '%$ch2%'
order by idx desc limit $idx, $pageSize";
$count="select count(*) tc from member0403 where name like '%$ch2%' ";
}else if($ch1=='age'){
$SQL="select * from member0403 where age like '%$ch2%'
order by idx desc limit $idx, $pageSize";
$count="select count(*) tc from member0403 where age like '%$ch2%' ";
}
$conn = new mysqli($servername, $username, $password, $dbname);
$result =$conn -> query($SQL);
$conn = new mysqli($servername, $username, $password, $dbname);
$result_count = $conn -> query($count);
$row_count = $result_count -> fetch_assoc();
$tc=$row_count['tc'];
// 총 페이지 수
$totalPage = ceil($tc/$pageSize);
// 현재 레코드
$nowRecord = $idx + 1;
// 현재 페이지
$nowPage = ceil($nowRecord / $pageSize);
// 페이지 가로 번호 시작
$startPage = floor(($nowPage - 1)/$pageListSize)*$pageListSize+1 ;
// 페이지 가로 번호 마지막
$endPage = $startPage + $pageListSize -1 ;
// 마지막 페이지
$endPageIdx = ($totalPage-1) * $pageSize;
?>
<section>
<br/>
<div align=center>
1. 페이지사이즈 : <?=$pageSize?>
2. 페이지 List 사이즈 : <?=$pageListSize?>
3. 전체 레코드 : <?=$tc?>
4. 총 페이지 수 : <?=$totalPage?><br/>
5. 현재 레코드 : <?=$nowRecord?>
6. 현재 페이지 : <?=$nowPage?>
<!-- [1] [11] [21] -->
7. 하단 가로 시작 : <?=$startPage?>
<!-- [10] [20] [30] -->
8. 하단 가로 끝 : <?=$endPage?>
<br/>
<h2>목록 보기 연습</h2>
<table id=tb border=1>
<tr>
<th>번호</th><th>이름</th><th>나이</th>
<th>암호</th>
<th>파일명</th>
</tr>
<?
while($row = $result -> fetch_assoc()) {
?>
<tr>
<td><?=$row['idx']?></td>
<td>
<a href=psd_edit0403.php?idx=<?=$row['idx']?>>
<?=$row['name']?></a>
</td>
<td><?=$row['age']?></td>
<td><?=$row['pwd1']?></td>
<td><?=$row['img']?></td>
</tr>
<?
}
?>
</table>
<!-- 처음 페이지 설정 -->
<? if($startPage <= 1){ ?>
처음
<? }else{ ?>
<a href=psd_list_page0406.php?idx=0&ch1=<?=$ch1?>&ch2=<?=$ch2?>>처음</a>
<? } ?>
<!-- 이전 페이지 설정 -->
<? if($startPage <= 1) { ?>
이전
<? }else{ ?>
<a href=psd_list_page0406.php?idx=<?=($startPage-2)*$pageSize?>&ch1=<?=$ch1?>&ch2=<?=$ch2?>>이전<?=$pageListSize?>페이지</a>
<? } ?>
<!-- 페이지 넘버 설정 -->
<?
for ($i = $startPage; $i <= $endPage ; $i++){
?>
<? if( $i <= $totalPage) {?>
<!-- 0, 10, 20 ... 으로 값이 넘어옴 -->
<a href=psd_list_page0406.php?idx=<?=($i-1)*$pageSize?>&ch1=<?=$ch1?>&ch2=<?=$ch2?>><?=$i?></a>
<?
}
}?>
<!-- 다음 페이지 설정 -->
<? if($endPage < $totalPage) { ?>
<a href=psd_list_page0406.php?idx=<?=$endPage*$pageSize?>&ch1=<?=$ch1?>&ch2=<?=$ch2?>>다음<?=$pageListSize?>페이지</a>
<? }else{ ?>
다음<?=$pageListSize?>페이지
<? } ?>
<!-- 마지막 페이지 설정 -->
<? if($endPageIdx < $nowRecord) {?>
마지막
<? }else{ ?>
<a href=psd_list_page0406.php?idx=<?=$endPageIdx?>&ch1=<?=$ch1?>&ch2=<?=$ch2?>>마지막</a>
<? } ?>
<!-- 검색 설정 -->
<form>
<select name=ch1>
<option value=name>이름</option>
<option value=age>나이</option>
</select>
<input type=text name=ch2>
<input type=submit value="검색하기">
</form>
</div>
<br/>
</section>
<?$conn->close();?>
<? include $_SERVER["DOCUMENT_ROOT"]."/include/bottom0403.php" ?>
<html>
<head>
<title> </title>
</head>
<style>
header{
/* 백그라운드 색상 검정(#000000) ~ 흰색(#ffffff) */
background:#3344ff;
/* 영역 높이 */
height:60px;
/* 텍스트 라인 높이(높이의 가운데를 기준으로 분할높이) */
line-height:60px;
/* 글자 크기 */
font-size:25px;
/* 글자 가운데 정렬 */
text-align:center;
/* 글자 색상 */
color:#ffffff;
}
nav{
background:#5533ff;
height:30px;
line-height:30px;
font-size:15px;
color:#ffffff;
}
section{
min-height:650px;
line-height:30px;
}
#sectionTitle{
font-size:20px;
}
footer{
background:#0066bb;
height:30px;
line-height:30px;
font-size:10px;
text-align:center;
color:#ffffff;
}
tr{
text-align:center;
}
</style>
</head>
<?
$servername = "localhost";
$username = "root";
$password = "autoset";
$dbname = "ppk";
$conn = new mysqli($servername, $username, $password, $dbname);
$SQL = "select sNo, sName, kor, eng, math, hist from examtbl order by sNo asc";
$result = $conn -> query($SQL);
?>
<body>
<header> (과정평가형 정보처리기능사) 성적조회 프로그램 ver1.0 </header>
<nav>
<a href=form0406.php>성적입력</a>
<a href=list0406.php>성적조회</a>
<a href=index0406.php>홈으로</a>
</nav>
<section>
<br/>
<div align=center id=sectionTitle> <b>고등학교 성적 조회 목록</b></div><br/>
<div id=sectionDiv align=center>
<table border=1 width=700>
<tr>
<th>순번</th><th>학년</th><th>반</th><th>번호</th><th>성명</th>
<th>국어</th><th>영어</th><th>수학</th><th>역사</th>
<th>총점</th><th>평균</th><th>평점</th>
</tr>
<?
// 순번
$i=0;
while($row = $result -> fetch_assoc()){
$i ++;
// 합계
$sum = $row['kor'] + $row['eng'] + $row['math'] + $row['hist'];
// 평균
$avg = $sum / 4;
// 점수별 학점 부여하기
if($avg >= 90){
$grade ='A';
}else if($avg >= 80){
$grade ='B';
}else if($avg >= 70){
$grade ='C';
}else{
$grade ='F';
}
// 총 누적 합계 구하기
// += : 누적합
$skor += $row['kor'];
$seng += $row['eng'];
$smath += $row['math'];
$shist += $row['hist'];
$ssum += $sum;
$savg += $avg;
// 평균, 총평균 값 구하기
// round(기본값 / 나눌값), 소숫점자리);
$akor = round($skor / $i, 2);
$aeng = round($seng / $i, 2);
$amath = floor($smath / $i);
$ahist = round($shist / $i, 2);
$asum = floor($ssum / $i);
$aavg = round($savg / $i, 3);
?>
<tr>
<!-- 학년, 반, 번호 구하기 / 데이터 값 불러오기 -->
<!-- substr(값, 시작, 길이) -->
<td><?=$i?></td>
<td><?=substr($row['sNo'],0,1)?></td>
<td><?=substr($row['sNo'],1,2)?></td>
<td><?=substr($row['sNo'],3,2)?></td>
<td><?=$row['sName']?></td><td><?=$row['kor']?></td>
<td><?=$row['eng']?></td><td><?=$row['math']?></td>
<td><?=$row['hist']?></td><td><?=$sum?></td>
<td><?=$avg?></td><td><?=$grade?></td>
</tr>
<? } ?>
<!-- 총 점수 합계 구하기 -->
<tr>
<td colspan=5> 총점</td>
<td><?=$skor?></td>
<td><?=$seng?></td>
<td><?=$smath?></td>
<td><?=$shist?></td>
<td><?=$ssum?></td>
<td><?=$savg?></td>
<td></td>
</tr>
<!-- 각 항목 평균과 총 평균 구하기 -->
<tr>
<td colspan=5> 총평균</td>
<td><?=$akor?></td>
<td><?=$aeng?></td>
<td><?=$amath?></td>
<td><?=$ahist?></td>
<td><?=$asum?></td>
<td><?=$aavg?></td>
<td></td>
</tr>
</table>
</div>
<br/>
</section>
</body>
<footer>
HRDKOREA Copyright(C)2018 All rights reserved. Human Resources Development Service of Korea
</footer>
</html>
오늘은 기존에 했던 페이지 나누기에서 넘버를 정하고, 페이지 사이즈를 구해
여러페이지를 넘기는 버튼을 만들었다.
웹개발을 할때 실용적으로 사용할 수 있는 부분인것 같다.
그리고 자격증 대비 겸 복습을 위하여 PHP와 SQL 쿼리문으로 테이블을 작성했다.
학년 반 번호를 기입할 때 여러 레코드를 묶어 사용하는
substr이 기억에 남는다.
다시 복습하며 암기하도록 해야겠다.