기록해! 정리해!

HTML -- 성적조회프로그램 Ver1.0 (4) 코드정리 본문

Visual studio (PHP)

HTML -- 성적조회프로그램 Ver1.0 (4) 코드정리

zsuling 2022. 6. 28. 09:39

index.php

<html>
<head>
<title> 성적처리 프로그램 </title>
<style>
header{
    background-color:blue;
    height: 63px;
    line-height: 63px; 
    color: #ffffff;
    font-size:28px;
    text-align:center;
}
nav{
    background-color:#00aaff;
    height: 30px;
    line-height: 30px;
    color: #ffffff;
    font-size:14px;
}
section{
    background-color:#cccccc;
    min-height:530px;
}
footer{
    background-color:blue;
    height: 45px;
    line-height: 45px; 
    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>
<body>
    <div id="body">
      <header> 학생 성적처리 프로그램 Ver.1.11 </header>
      <nav> 
        &emsp;&emsp;&emsp; 
        <a href=#>학생등록</a>&emsp;
        <a href=#>학생목록/수정</a> &emsp; 
        <a href=insert.php>빅데이터추가</a> &emsp; 
        <a href=list1.php>페이지나누기1</a> &emsp; 
        <a href=list2.php>페이지나누기2</a> &emsp; 
        <a href=index.php>홈으로</a> 
        </nav>
      <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>
      <footer> HRDKOREA Copyrightⓒ2022 ALL rights reserved Development Services of Korea
         </footer>
    </div>
</body>
</html>

insert.php

<html>
<head>
<title> 성적처리 프로그램 </title>
<style>
header{
    background-color:blue;
    height: 63px;
    line-height: 63px; 
    color: #ffffff;
    font-size:28px;
    text-align:center;
}
nav{
    background-color:#00aaff;
    height: 30px;
    line-height: 30px;
    color: #ffffff;
    font-size:14px;
}
section{
    background-color:#cccccc;
    min-height:530px;
}
footer{
    background-color:blue;
    height: 45px;
    line-height: 45px; 
    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>
<body>
    <div id="body">
      <header> 학생 성적처리 프로그램 Ver.1.11 </header>
      <nav> 
        &emsp;&emsp;&emsp; 
        <a href=#>학생등록</a>&emsp;
        <a href=#>학생목록/수정</a> &emsp; 
        <a href=insert.php>빅데이터추가</a> &emsp; 
        <a href=list1.php>페이지나누기1</a> &emsp; 
        <a href=list2.php>페이지나누기2</a> &emsp; 
        <a href=index.php>홈으로</a> 
        </nav>
      <section>  
        <br><br>
        <div align=center><font size=4>
           <b>빅데이터추가</b>
        </font></div>
        <div align=center>
        <br>

         <?
         for($i=1 ; $i <= 34 ; $i++ ){
         $nameRand1 = mt_rand(0,4);
         $nameRand2 = mt_rand(0,4);
         $name1 = array('하니','똘이','영심이','만수','지효');
         $name2 = array('하나','둘','셋','넷','다섯');        
         
         $titleRand1 = mt_rand(0,4);
         $titleRand2 = mt_rand(0,4);
         $title1 = array('ASP','JSP','PHP','JAVA','C#');
         $title2 = array('초급','중급','고급','심화','실무');

         $etcRand1 = mt_rand(0,6);
         $etcRand2 = mt_rand(0,4);
         $etc1 = array('서울','경기','강원','제주','대전','울릉도','독도');
         $etc2 = array('산','바다','강','하늘','땅');

         $name = $name1[$nameRand1].$name2[$nameRand2];
         $age = mt_rand(11, 19); 
         $title = $title1[$titleRand1]." ".$title2[$titleRand2];
         $etc = $etc1[$etcRand1]." ".$etc2[$etcRand2];

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

         <br> <br> <br> <br> <br>
         <h1>빅데이터 저장 완료 </h1>

        </div>    
        <br>
     </section>
      <footer> HRDKOREA Copyrightⓒ2022 ALL rights reserved Development Services of Korea
         </footer>
    </div>
</body>
</html>

list1.php

<html>
<head>
<title> 성적처리 프로그램 </title>
<style>
header{
    background-color:blue;
    height: 63px;
    line-height: 63px; 
    color: #ffffff;
    font-size:28px;
    text-align:center;
}
nav{
    background-color:#00aaff;
    height: 30px;
    line-height: 30px;
    color: #ffffff;
    font-size:14px;
}
section{
    background-color:#cccccc;
    min-height:530px;
}
footer{
    background-color:blue;
    height: 45px;
    line-height: 45px; 
    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>
<body>
    <div id="body">
      <header> 학생 성적처리 프로그램 Ver.1.11 </header>
      <nav> 
        &emsp;&emsp;&emsp; 
        <a href=#>학생등록</a>&emsp;
        <a href=#>학생목록/수정</a> &emsp; 
        <a href=insert.php>빅데이터추가</a> &emsp; 
        <a href=list1.php>페이지나누기1</a> &emsp; 
        <a href=list2.php>페이지나누기2</a> &emsp; 
        <a href=index.php>홈으로</a> 
        </nav>
      <section>  
        <br><br>
        <div align=center><font size=4>
           <b>학생 목록 보기 1</b>
        </font></div>
        <div align=center>
        <br>
        <?

    
    $page_size = 10;

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

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

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

     $SQL = " select * from board2 " ;
     $SQLEnd = " order  by idx  desc  limit $idx, $page_size  " ;
     $tc_sql = " select count(*) tc from board2 ";

     if ($ch1 == "") {
       $SQL =  $SQL.$SQLEnd ;
       $tc_sql = $tc_sql;
     }else if($ch1 == "name") {
       $SQL =  $SQL." where name like '%$ch2%' ".$SQLEnd ;
       $tc_sql = $tc_sql . " where name like '%$ch2%' ";
       
     }else if($ch1 == "title") {
       $SQL =  $SQL." where title like '%$ch2%' ".$SQLEnd ;
       $tc_sql = $tc_sql . " where title like '%$ch2%' ";
     }

     $tc_result = $conn -> query($tc_sql);
     $tc_row = $tc_result -> fetch_array();
     $result = $conn -> query($SQL);
     
   
     $total_page = ceil($tc_row['tc']/$page_size);
     $now_page = ($idx/$page_size) + 1 ;


   ?>
   전체레코드수 : <?=$tc_row['tc']?> (<?=$now_page?> / <?=$total_page?>)
   <table  border=1  width=500>
   <tr>
       <td>순번</td><td>번호</td><td>이름</td>
       <td>나이</td><td>제목</td> 
   </tr>
   <? 
   $i = 0;
   // $row = $result ->fetch_assoc() : 칼럼명으로만 출력 가능
   // $row = mysqli_fetch_row($result) : 순서로만 출력 가능.
   // $row = $result ->fetch_array() : 순서와 칼럼명 모두 가능.
   while($row = $result ->fetch_array() ) {  
    $i ++ ;
   ?>
   <tr>
   <td><?=$i ?></td>
       <td><?=$row[0] ?></td>
       <td><?=$row['name'] ?></td>
       <td><?=$row['age'] ?></td>
       <td><?=$row["title"] ?></td> 
   </tr>
   <?}?>

   </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>  &emsp;
   <? if($idx < $page_size){ 
    echo "이전 &emsp;" ;
    }else{ 
   ?>
    <a href=list1.php?idx=<?=$idx-$page_size?>&ch1=<?=$ch1?>&ch2=<?=$ch2?>>이전</a> &emsp;
   <? } ?>
  <? if($now_page == $total_page) {
   ?> 다음 &emsp;
  <? }else{ ?>
    <a href=list1.php?idx=<?=$idx+$page_size?>&ch1=<?=$ch1?>&ch2=<?=$ch2?>>다음</a> &emsp;
  <? } ?>
  <?
  $end_page=($total_page -1) * $page_size ; 
  ?>
  <a href=list1.php?idx=<?=$end_page?>&ch1=<?=$ch1?>&ch2=<?=$ch2?>> 마지막으로 
    
 

</div> 
<br>   
</section>
<footer> 
   HRDKOREA Copyrightⓒ2022 ALL rights resources Development Service of Korea  
 </footer> 
</div>
</body>
</html>

list2.php

<html>
<head>
<title> 성적처리 프로그램 </title>
<style>
header{
    background-color:blue;
    height: 63px;
    line-height: 63px; 
    color: #ffffff;
    font-size:28px;
    text-align:center;
}
nav{
    background-color:#00aaff;
    height: 30px;
    line-height: 30px;
    color: #ffffff;
    font-size:14px;
}
section{
    background-color:#cccccc;
    min-height:530px;
}
footer{
    background-color:blue;
    height: 45px;
    line-height: 45px; 
    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>
<body>
    <div id="body">
      <header> 학생 성적처리 프로그램 Ver.1.11 </header>
      <nav> 
        &emsp;&emsp;&emsp; 
        <a href=#>학생등록</a>&emsp;
        <a href=#>학생목록/수정</a> &emsp; 
        <a href=insert.php>빅데이터추가</a> &emsp; 
        <a href=list1.php>페이지나누기1</a> &emsp; 
        <a href=list2.php>페이지나누기2</a> &emsp; 
        <a href=index.php>홈으로</a> 
        </nav>
      <section>  
        <br><br>
        <div align=center><font size=4>
           <b>학생 목록 보기 1</b>
        </font></div>
        <div align=center>
        <br>
        <?

    // 1. 페이지 사이즈
    $page_size = 10;
    // 2. 페이지 리스트 사이즈 
    $page_list_size = 10;

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

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

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

     $SQL = " select * from board2 " ;
     $SQLEnd = " order  by idx  asc  limit $idx, $page_size  " ;
     $tc_sql = " select count(*) tc from board2 ";

     if ($ch1 == "") {
       $SQL =  $SQL.$SQLEnd ;
       $tc_sql = $tc_sql;
     }else if($ch1 == "name") {
       $SQL =  $SQL." where name like '%$ch2%' ".$SQLEnd ;
       $tc_sql = $tc_sql . " where name like '%$ch2%' ";
       
     }else if($ch1 == "title") {
       $SQL =  $SQL." where title like '%$ch2%' ".$SQLEnd ;
       $tc_sql = $tc_sql . " where title like '%$ch2%' ";
     }

     $tc_result = $conn -> query($tc_sql);
     $tc_row = $tc_result -> fetch_array();
     $result = $conn -> query($SQL);

     //3. 전체 레코드 수
     $tc= $tc_row['tc'];
     
    // 4. 총 페이지 수
     $total_page = ceil($tc/$page_size);

     // 5. 현재레코드
     $idx = $idx+1;

     // 6. 현재페이지  
     $now_page = ceil($idx/$page_size) ;

     // 7. 하단가로 시작
     $start_page = floor(($now_page-1) / $page_list_size)* $page_list_size+1;
     // 8. 하단가로 마지막
     $end_page = $start_page + $page_list_size - 1;

   ?>
   &emsp; 1. 페이지 사이즈 <?=$page_size?>
   &emsp; 2. 페이지 List 사이즈 <?=$page_list_size?>
   &emsp; 3. 전체 레코드 수 <?=$tc_row['tc']?>
   &emsp; 4. 총 페이지 수 <?=$total_page?> <br>
   &emsp; 5. 현재 레코드 <?=$idx?>
   &emsp; 6. 현재 페이지 <?=$now_page?>
   &emsp; 7. 하단가로시작 <?=$start_page?>
   &emsp; 8. 하단가로마지막 <?=$end_page?>
  
   <table  border=1  width=500>
   <tr>
       <td>순번</td><td>번호</td><td>이름</td>
       <td>나이</td><td>제목</td> 
   </tr>
   <? 
   $i = 0;
   // $row = $result ->fetch_assoc() : 칼럼명으로만 출력 가능
   // $row = mysqli_fetch_row($result) : 순서로만 출력 가능.
   // $row = $result ->fetch_array() : 순서와 칼럼명 모두 가능.
   while($row = $result ->fetch_array() ) {  
    $i ++ ;
   ?>
   <tr>
   <td><?=$i ?></td>
       <td><?=$row[0] ?></td>
       <td><?=$row['name'] ?></td>
       <td><?=$row['age'] ?></td>
       <td><?=$row["title"] ?></td> 
   </tr>
   <?}?>

   </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>  &emsp;
   <? if($idx == 1){ 
    echo "이전 $page_list_size &emsp;" ;
    }else{ 
   ?>
    <a href=list2.php?idx=<?=($start_page-2)*$page_list_size?>&ch1=<?=$ch1?>&ch2=<?=$ch2?>>이전<?=$page_list_size?></a> &emsp;
   <? } ?>
<?php
for($i = $start_page ; $i <= $end_page ; $i++ ){
    if($i <= $total_page){
   ?>    
   <a href=list2.php?idx=<?=($i-1)*$page_size?>> <?=$i?></a> 
  <? 
  } 
 } ?>
&emsp;
 <? if($now_page == $total_page) {
   ?> 다음 <?$page_list_size?> &emsp;
  <? }else{ ?>
    <a href=list2.php?idx=<?=$end_page*$page_list_size?>&ch1=<?=$ch1?>&ch2=<?=$ch2?>>다음<?=$page_list_size?></a> &emsp;
  <? } ?>
  <?
  $end=($total_page -1) * $page_size ; 
  ?>
  <a href=list2.php?idx=<?=$end?>&ch1=<?=$ch1?>&ch2=<?=$ch2?>> 마지막으로 
    
 

</div> 
<br>   
</section>
<footer> 
   HRDKOREA Copyrightⓒ2022 ALL rights resources Development Service of Korea  
 </footer> 
</div>
</body>
</html>
Comments