기록해! 정리해!

HTML --페이지 나누기,로그인,로그아웃 코드정리 본문

Visual studio (PHP)

HTML --페이지 나누기,로그인,로그아웃 코드정리

zsuling 2022. 6. 29. 09:44

index.php

<? include $_SERVER["DOCUMENT_ROOT"]."/D_include/top.php"?>
<section>

<br><br>

<div align=center><font size=4>
           <b>고등학교 성적처리 프로그램</b>
        </font></div>
        <div>
        <br>
        &emsp; 1. 학생 성적 정보 테이블을 생성한다. <br>
        &emsp; 2. 학생 성적 테이블에 샘플데이터를 SQL문을 이용하여 추가한다. <br>
        &emsp; 3. 주어진 화면 디자인을 이용하여 화면을 디자인한다. <br>
        &emsp; 4. 업무 여건에 따라 프로그램을 작성한다. <br>
        </div>    
        <br>

</section>
<? include $_SERVER["DOCUMENT_ROOT"]."/D_include/bottom.php"?>

 

D_include

 

top.php

<? session_start(); ?>
<html>
<head>
<style>
header{
    background-color:blue;
    height:65px;
    line-height:65px;
    color:#ffffff;
    font-size:30px;
    text-align:center;
}   
nav{
    background-color:#00aaff;
    height:30px;
    line-height:30px;
    color:#ffffff;
    font-size:13px;
} 
section{
    background-color:#cccccc;
    min-height:530px;
}
footer{
    background-color:#0000ff;
    height:40px;
    line-height:40px;
    color:#ffffff;
    font-size:16px;
    text-align:center;
}
#body{
 width:90%;
 margin:auto;
}
 a:link, a:visited
  {
    color: #ffffff;
    text-decoration: none;
  }
 a:hover, a:active{
    color:#000000;
    text-decoration-line: underline;
  }
</style> 
</head>
<?
 $host = $_SERVER['HTTP_HOST'];
 $path = "http://".$host;
 $rootPath = $_SERVER["DOCUMENT_ROOT"];
?>
<body>
<div id= "body">
<header>
학생 성적 처리 프로그램 Ver.1.11
</header>
<nav> &emsp;&emsp;&emsp; 
      <a href="<?=$path?>/A_school/form.php">학생등록</a> &nbsp;  
      <a href="<?=$path?>/A_school/list.php">학생목록/수정</a>&emsp;&emsp;
      
      <? if ($_SESSION["id"] == "admin" ) {  ?> 
      <a href="<?=$path?>/B_big/insert.php">빅데이터추가</a> &nbsp; 
      <a href="<?=$path?>/B_big/list1.php">페이지나누기1</a> &nbsp; 
      <a href="<?=$path?>/B_big/list2.php">페이지나누기2</a> &emsp;&emsp; 
      <? } ?>

      <? if ($_SESSION["id"] != "admin" ) {  ?> 
      <a href="<?=$path?>/C_admin/login.php">로그인</a>  &nbsp;   
      <?  } else { ?> 
      <a href="<?=$path?>/C_admin/logout.php">로그아웃</a> &emsp;&emsp; 
      <? } ?>
      
      <a href="<?=$path?>/index.php">홈으로</a>  

</nav>

bottom.php

<footer>
HRDKOREA Copyrightⓒ2018 ALL rights reserved. Human Resources Development Services of Korea
</footer>
</div>
</body>
    </html>

B_big

 

insert.php

<? include $_SERVER["DOCUMENT_ROOT"]."/D_include/top.php"?>
<section>

<br><br>

<div align=center><font size=4><b>빅데이터 등록</b></font></div>
<div align=center>
<br><br>
<?php
for ($i=0 ; $i <= 11; $i++ ){
    
    $name_rand=mt_rand(0,9);
    $name_array=array('하나','둘','셋','넷','다섯','여섯','일곱','여덟','아홉','열') ;
    $name=$name_array[$name_rand];

    $age=mt_rand(11,25);
    
    $title_rand=mt_rand(0,4);
    $title_array=array('asp 중급','자바 초급','웹프로그램 고급','전산 실무', '데이터베이스 튜닝');
    $title=$title_array[$title_rand];

    $etc_rand=mt_rand(0,1);
    $etc_array=array('전공학생', '비전공학생');
    $etc=$etc_array[$etc_rand];

    $conn = new mysqli("localhost","root","autoset","korea");
    $SQL = " insert into board0628 (name, age, title, etc) 
             values ('$name', '$age', '$title', '$etc')";
    $conn -> query($SQL);
    echo $i."&nbsp;";
    $conn -> close();
}
?>
</div>    
<br>

</section>
<? include $_SERVER["DOCUMENT_ROOT"]."/D_include/bottom.php"?>

list1.php

<? include $_SERVER["DOCUMENT_ROOT"]."/D_include/top.php"?>
<?
$conn = new mysqli("localhost","root","autoset","korea");

$ch1 = $_GET['ch1'];
$ch2 = $_GET['ch2'];

$page_size = 10;

if($_GET['idx']==""){
 $idx=0;
}else{
  $idx=$_GET['idx'];
}

$SQL1 = " select idx, name, age, title, etc from board0628 ";
$SQL2 =  "  order by idx desc limit $idx,  $page_size " ;
//전체레코드 수
$SQL_tc1 = " select count(*)tc from board0628 " ;
        if ($ch1 == ""){
            $SQL = $SQL1 . $SQL2 ;
            $SQL_tc = $SQL_tc1 ;
           }else if($ch1 == "name"){
            $SQL = $SQL1 ." where name like '%$ch2%' " . $SQL2;
            //조건에 맞는 전체 레코드 수
            $SQL_tc = $SQL_tc1 . " where name like '%$ch2%' " ;
           }else if($ch1 == "title"){
            $SQL = $SQL1 ." where title like '%$ch2%' " . $SQL2;
            $SQL_tc = $SQL_tc1 . " where title like '%$ch2%' " ;
           }

$result_tc = $conn -> query($SQL_tc);
$rs_tc = $result_tc -> fetch_assoc();
$tc=$rs_tc['tc'];

$total_page = ceil ($tc / $page_size) ;
$now_page = $idx / $page_size + 1 ;

$result = $conn -> query($SQL);

?>

<section>

<br><br>
<div align=center><font size=4><b>목록보기 (페이지나누기1)</b></font></div>
<div align=center>
<br>
전체레코드:<?=$tc?> &emsp; 현재페이지:<?=$now_page?> / 전체페이지:<?=$total_page?>
<table border=1 width=500px>
<tr> <td>순번</td> <td>번호</td> <td>이름</td> <td>나이</td> <td>제목</td> <td>특이사항</td> 
<?
$i = 1 ;
 while( $rs = $result -> fetch_assoc() ) {

?>
 <tr>
 <td align=center> <?=$i?> </td>
 <td> <?=$rs['idx']?> </td>
 <td>  <?=$rs['name']?>
 <td> <?=$rs['age']?>
 <td> <?=$rs['title']?>
 <td> 
 <a href=delete.php?delidx=<?=$rs['idx']?>
  &ch1=<?=$ch1?>&ch2=<?=$ch2?>&idx=<?=$_GET['idx']?>><?=$rs['etc']?></a></td>
</tr>
 <? 
$i ++ ;
}?>

</table>
<form>
    <select name=ch1>
        <option value=name>이름</option>
        <option value=title>제목</option>
    </select>
    <input type=text name=ch2>
    <input type=submit value="검색하기">
 </form>    
 <a href=list1.php?idx=0&ch1=<?=$ch1?>&ch2=<?=$ch2?>>처음으로</a>&nbsp;&nbsp;

 <? if($idx == 0){ ?>
     이전 &nbsp;&nbsp;
 <? }else{ ?>
 <a href=list1.php?idx=<?=$idx-$page_size?>&ch1=<?=$ch1?>&ch2=<?=$ch2?>>이전</a>&nbsp;&nbsp;
 <? } ?>

 <? if($total_page != $now_page){ ?>
    <a href=list1.php?idx=<?=$idx+$page_size?>&ch1=<?=$ch1?>&ch2=<?=$ch2?>>다음</a>&nbsp;&nbsp;
 <? }else{ ?>
    다음&nbsp;&nbsp;  
 <? } ?>
 
 <? $endPage = ($total_page-1)*$page_size ;?>
 <a href=list1.php?idx=<?=$endPage?>&ch1=<?=$ch1?>&ch2=<?=$ch2?>>마지막으로</a>
 </div>    
<br>

</section>


<? include $_SERVER["DOCUMENT_ROOT"]."/D_include/bottom.php"?>

list2.php

<? include $_SERVER["DOCUMENT_ROOT"]."/D_include/top.php"?>
<?
$conn = new mysqli("localhost","root","autoset","korea");

$ch1 = $_GET['ch1'];
$ch2 = $_GET['ch2'];

//1.페이지 사이즈
$page_size = 10;

//2. 페이지 List 사이즈
$page_List_size = 10;

if($_GET['idx']==""){
 $idx=0;
}else{
  $idx=$_GET['idx'];
}

$SQL1 = " select idx, name, age, title, etc from board0628 ";
$SQL2 =  "  order by idx desc limit $idx,  $page_size " ;
//전체레코드 수
$SQL_tc1 = " select count(*)tc from board0628 " ;
        if ($ch1 == ""){
            $SQL = $SQL1 . $SQL2 ;
            $SQL_tc = $SQL_tc1 ;
           }else if($ch1 == "name"){
            $SQL = $SQL1 ." where name like '%$ch2%' " . $SQL2;
            //조건에 맞는 전체 레코드 수
            $SQL_tc = $SQL_tc1 . " where name like '%$ch2%' " ;
           }else if($ch1 == "title"){
            $SQL = $SQL1 ." where title like '%$ch2%' " . $SQL2;
            $SQL_tc = $SQL_tc1 . " where title like '%$ch2%' " ;
           }

$result_tc = $conn -> query($SQL_tc);
$rs_tc = $result_tc -> fetch_assoc();
//3. 전체레코드 수
$tc=$rs_tc['tc'];
//4. 총 페이지 수
$total_page = ceil ($tc / $page_size) ;
//5. 현재 레코드
$now_record = $idx + 1 ;
//6. 현재 페이지
$now_page = ceil($now_record / $page_size) ;

$result = $conn -> query($SQL);

//7. 하단가로 시작
$start_page = floor(($now_page-1)/$page_List_size)*$page_List_size + 1 ;

//8. 하단가로 마지막
$end_page = $start_page + $page_List_size - 1 ; 

?>

<section>

<br><br>
<div align=center><font size=4><b>목록보기 (페이지나누기2)</b></font></div>
<div align=center>
<br>
1.페이지 사이즈 <?=$page_size?> &nbsp;&nbsp;
2.페이지List사이즈 <?=$page_List_size?> &nbsp;&nbsp;
3.전체레코드수 <?=$tc?> &nbsp;&nbsp;
4.총 페이지 수 <?=$total_page?> <br>
5.현재 레코드 <?$now_record?> &nbsp;&nbsp;
6.현재 페이지 <?=$now_page?>&nbsp;&nbsp;
7.하단가로시작 <?=$start_page?>&nbsp;&nbsp;
8.하단가로마지막 <?=$end_page?>

<table border=1 width=500px>
<tr> <td>순번</td> <td>번호</td> <td>이름</td> <td>나이</td> <td>제목</td> <td>특이사항</td> 
<?
$i = 1 ;
 while( $rs = $result -> fetch_assoc() ) {

?>
 <tr>
 <td align=center> <?=$i?> </td>
 <td> <?=$rs['idx']?> </td>
 <td>  <?=$rs['name']?>
 <td> <?=$rs['age']?>
 <td> <?=$rs['title']?>
 <td> 
 <a href=delete.php?delidx=<?=$rs['idx']?>
  &ch1=<?=$ch1?>&ch2=<?=$ch2?>&idx=<?=$_GET['idx']?>><?=$rs['etc']?></a></td>
</tr>
 <? 
$i ++ ;
}?>

</table>
<form>
    <select name=ch1>
        <option value=name>이름</option>
        <option value=title>제목</option>
    </select>
    <input type=text name=ch2>
    <input type=submit value="검색하기">
 </form>    
 <a href=list2.php?idx=0&ch1=<?=$ch1?>&ch2=<?=$ch2?>>처음으로</a>&nbsp;&nbsp;

 <? if($start_page == 1){ ?>
     이전 &nbsp;&nbsp;
 <? }else{ ?>
 <a href=list2.php?idx=<?=($start_page-2)*$page_List_size?>&ch1=<?=$ch1?>&ch2=<?=$ch2?>>이전<?=$page_List_size?>페이지</a>&nbsp;&nbsp;
 <? } ?>

 <? 
 for ($i = $start_page ; $i <= $end_page ; $i ++ ){
     if($i <= $total_page){
      ?>
       <a href=list2.php?idx=<?=($i-1)*$page_size?>><?=$i?></a>&nbsp;&nbsp;
      <?
     }
 }
 ?>

 <? if($end_page < $total_page){ ?>
    <a href=list2.php?idx=<?=$end_page*$page_List_size?>&ch1=<?=$ch1?>&ch2=<?=$ch2?>>다음<?=$page_List_size?>페이지</a>&nbsp;&nbsp;
 <? }else{ ?>
    다음 &nbsp;&nbsp;  
 <? } ?>
 
 <? $endPage = ($total_page-1)*$page_size ;?>
 <a href=list2.php?idx=<?=$endPage?>&ch1=<?=$ch1?>&ch2=<?=$ch2?>>마지막으로</a>
 </div>    
<br>

</section>


<? include $_SERVER["DOCUMENT_ROOT"]."/D_include/bottom.php"?>

delete.php

<? include $_SERVER["DOCUMENT_ROOT"]."/D_include/top.php"?>
<?
$delidx = $_GET['delidx'];
$idx = $_GET['idx'];
$ch1 = $_GET['ch1'];
$ch2 = $_GET['ch2'];

$conn = new mysqli("localhost","root","autoset","korea");

  $SQL ="delete from board0628 where idx ='$delidx' " ;

  $conn -> query($SQL);
  $conn -> close();

?>
<script>
    location.href="list1.php?idx=<?=$idx?>&ch1=<?=$ch1?>&ch2=<?=$ch2?>"
</script>

C_admin

 

login.php

<? include  $_SERVER["DOCUMENT_ROOT"]."/D_include/top.php" ?>
<section> 

<br><br>    
<div align=center> <font size=4> <b> 로그인 </b></font>  </div>    
<div align=center>
   <br> 
     <form action=login_ok.php>
       <table BORDER=1 width=300  height=150>
        <tr><td>아이디</td><td><input type=text name=id > </td></tr> 
        <tr><td>암호</td><td><input type=text name=pwd > </td></tr> 
        <tr><td colspan=2 align=center><input type=submit value="로그인" > </td></tr> 
       </table>
     </form>
</div> 
<br>   

</section>
<? include $_SERVER["DOCUMENT_ROOT"]."/D_include/bottom.php" ?>

logout.php

<? session_start(); ?>

<? include  $_SERVER["DOCUMENT_ROOT"]."/D_include/top.php" ?>
<section> 

<br><br>    
<div align=center> <font size=4> <b> 로그아웃 </b></font>  </div>    
<div align=center>
   <br><br><br><br><br>
   <h1> 로그아웃 완료 !!! </h1>
   <? 
     $_SESSION["id"] == " ";  //  값을 공백으로 변경
     session_unset();  // 세션 비우기 
     session_destroy(); // 세션 제거하기
     
     header('Location:http://127.0.0.1/index.php');
     exit;

   ?>
   
</div> 
<br>   

</section>
<? include $_SERVER["DOCUMENT_ROOT"]."/D_include/bottom.php" ?>

로그인 상태

로그아웃 상태

list2

Comments