기록해! 정리해!

HTML -- 학생 성적처리 ver 11 코드정리 본문

Visual studio (PHP)

HTML -- 학생 성적처리 ver 11 코드정리

zsuling 2022. 6. 20. 09:45

2022.06.17 - [Visual studio] - HTML --학생 성적처리 ver 11 (폼태그, 자바스크립트,오토셋)

 

HTML --학생 성적처리 ver 11 (폼태그, 자바스크립트,오토셋)

º 순서 html -> head / body -> body ( header / nav / section / footer ) -> head (style) -> style ( header / nav / section / footer ) -> div는 영역으로 묶어주고 싶은 곳 묶어주면 됨 body 부분을 묶어..

apr49.tistory.com

 

 

º index.php

<? 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 "bottom.php>

 

º top.php

<html>
<head>
<style>
header{
    background-color:blue;  /*바탕 색깔*/
    height:60px;            /*영역의 높이*/
    line-height:60px;       /*한글자의 높이*/
    color:#ffffff;          /*글자색깔*/
    font-size:28px;         /*글자 크기*/
    text-align:center;      /*가운데 정렬*/
}
nav{
    background-color:#6699ff;
    height:25px;
    line-height:25px;
    font-size:12px;
}
section{
    background-color:#cccccc;
    min-height:550px;
}
footer{
    background-color:#3333ff;
    height:30px;
    line-height:30px;
    text-align:center;
    font-size:14px; 
}
#body{
    width:90%;
    margin:auto;
}
</style>        
</head>
<body>
<div id="body">
<header>
 학생 성적처리 프로그램 Ver.1.11   
</header>
<nav>
 &emsp;&emsp;&emsp; 
 <a href=form.php>학생등록</a>&emsp;
 <a href=list.php>학생목록/수정</a>&emsp;
 <a href=index.php>홈으로</a>
</nav>

º bottom.php

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

º edit.php

<? include "top.php" ?>

<?
$servername = "localhost" ;
$username = "root";
$password ="autoset";
$dbname="korea";

$conn = new mysqli($servername, $username, $password, $dbname ); 
?>

<?
 $sno = $_REQUEST['sno'];

   $SQL = "select  *  from examtbl where sno= $sno" ;
   $result = $conn -> query($SQL);
   $row = $result -> fetch_assoc();
   $sno = $row['sno'];
   $sname = $row['sname'];
   $kor = $row['kor'];
   $eng = $row['eng'];
   $math = $row['math'];
   $hist = $row['hist'];
?>

<script>
    function ck1(){ 
        if(f1.sno.value==""){
        alert("학번을 입력해주세요");
        f1.sno.focus();
        return false;

         }else if(f1.sname.value.length <= 2){
        alert("이름을 3자 이상 입력해주세요");
        f1.sname.value==""
        f1.sname.focus();
        return false;

        }else{
        alert("성적 입력이 완료되었습니다");
       }
    
    }
        
        
  
</script>
<section>
<br><br>
<div align=center>
 <font size=4> <b> 성적 수정 하기 </b> </font>
</div>
<div> 
    <br>
    <form name=f1 onSubmit="return ck1()"
    method=get
    action="update_ok.php">
    <table border="1" align=center>
        <tr><td>학번</td><td><input type=text name=sno value="<?=$sno?>"></td></tr>
        <tr><td>성명</td><td><input type=text name=sname value="<?=$sname?>"></td></tr>
        <tr><td>국어</td><td><input type=text name=kor value="<?=$kor?>"></td></tr>
        <tr><td>영어</td><td><input type=text name=eng value="<?=$eng?>"></td></tr>
        <tr><td>수학</td><td><input type=text name=math value="<?=$math?>"></td></tr>
        <tr><td>역사</td><td><input type=text name=hist value="<?=$hist?>"></td></tr>
        <tr><td colspan="2" align="center">
            <input type=submit value="성적 수정">
        </td></tr>
    </table>
    </form>
    </div>
<br>
</section>
<? include "bottom.php" ?>

º form.php

<? include "top.php" ?>

<script>
    function ck1(){ 
        if(f1.sno.value==""){
        alert("학번을 입력해주세요");
        f1.sno.focus();
        return false;

         }else if(f1.sname.value.length <= 2){
        alert("이름을 3자 이상 입력해주세요");
        f1.sname.value==""
        f1.sname.focus();
        return false;

        }else{
        alert("성적 입력이 완료되었습니다");
       }
    
    }
        
        
  
</script>
<section>
<br><br>
<div align=center>
 <font size=4> <b> 성적 입력 하기 </b> </font>
</div>
<div> 
    <br>
    <form name=f1 onSubmit="return ck1()"
    method=get
    action="form_ok.php">
    <table border="1" align=center>
        <tr><td>학번</td><td><input type=text name=sno></td></tr>
        <tr><td>성명</td><td><input type=text name=sname></td></tr>
        <tr><td>국어</td><td><input type=text name=kor></td></tr>
        <tr><td>영어</td><td><input type=text name=eng></td></tr>
        <tr><td>수학</td><td><input type=text name=math></td></tr>
        <tr><td>역사</td><td><input type=text name=hist></td></tr>
        <tr><td colspan="2" align="center">
            <input type=submit value="성적저장">
        </td></tr>
    </table>
    </form>
    </div>
<br>
</section>
<? include "bottom.php" ?>

º form_ok.php

<?
$servername = "localhost";
$username = "root";
$password = "autoset";
$dbname = "korea";

$conn = new mysqli($servername, $username, $password, $dbname);
?>

<?
 $sno = $_GET['sno'];
 $sname = $_GET['sname'];
 $kor = $_GET['kor'];
 $eng = $_GET['eng'];
 $math = $_GET['math'];
 $hist = $_GET['hist'];
 
 $SQL = "insert into examtbl 
         values ('$sno','$sname','$kor','$eng','$math','$hist')";
 echo $SQL;
 $conn -> query($SQL);
?>

º list.php

<? include "top.php" ?>

<?
$servername = "localhost" ;
$username = "root";
$password ="autoset";
$dbname="korea";

$conn = new mysqli($servername, $username, $password, $dbname ); 
?>

<?
   $SQL = "select  *  from examtbl order by sno desc" ;
   $result = $conn -> query($SQL);
?>

<style>
#tr1{
    background-color:#ffaaaa;
}
#tr2{
    background-color:#aaaaff;
}
tr{
    text-align:center;
}
</style>  


<section>
<br><br>    
<div align=center> <font size=4> <b> 성적 목록 보기  </b></font>  </div>    
<div align=center>
   <br> 
   <table border=1>
     <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>      
     <? 
        $sum = 0;  $avg = 0.0 ;  $i =1 ;

        $skor=0; $seng=0 ; $smath=0; $shist=0;
        $ssum=0 ; $savg=0;

        $askor=0; $aseng=0 ; $asmath=0; $ashist=0;
        $assum=0 ; $asavg=0;

        while( $row = $result -> fetch_assoc()) {
               
        if ($i %2 == 1) {
           $bg = 'tr1' ;  
        } else{
            $bg = 'tr2' ; 
        }

        $sum = $row['kor'] + $row['eng'] + $row['math']+ $row['hist'];
        $avg = round( $sum / 4 , 1) ;  

        $skor = $skor + $row['kor'];
        $seng = $seng + $row['eng'];
        $smath = $smath+ $row['math'];
        $shist = $shist + $row['hist'];
        $ssum = $ssum + $sum;
        $savg = $savg + $avg ;
               
        $askor = round($skor / $i ,2);
        $aseng = round($seng / $i ,2);
        $asmath = round($smath / $i ,2);
        $ashist = round($shist / $i ,2); 
        $assum = round($ssum / $i ,2);
        $asavg = round($savg / $i ,2);

        if ($avg >= 90){
          $G ='A' ;
        } else if ($avg >= 80) {
          $G ='B' ;
        } else if ($avg >= 70){
          $G ='C' ;
        } else {
          $G ='F' ;
        }

     ?>
     <tr id="<?=$bg?>" >
     <td> &nbsp;A<?=$i?>  </td>
     <td> &nbsp;<?=substr($row['sno'],0,1)?>  </td>
     <td> &nbsp;<?=substr($row['sno'],1,2)?>  </td>
     <td> &nbsp;<?=substr($row['sno'],3,2)?>  </td>
     <td>
        <a href="edit.php?sno=<?=$row['sno']?>"> 
        <?=$row['sname']?> </a> 
     </td>
     <td><?=$row['kor']?> </td> <td><?=$row['eng']?> </td><td> <?=$row['math']?></td>
     <td><?=$row['hist']?> </td>
     <td><?=$sum?> </td>
     <td><?=$avg?> </td>
     <td><?=$G?> </td>
     </tr>

    <? 
       $i = $i + 1 ; 

       }
    ?>

     <tr>
     <td> &nbsp;  </td>
     <td> &nbsp;  </td>
     <td> &nbsp;  </td>
     <td> &nbsp;  </td>
       <td> 총점 </td>
     <td><?=$skor?> </td>      <td><?=$seng?> </td>
     <td><?=$smath?></td>      <td><?=$shist?> </td>
     <td><?=$ssum?> </td>      <td><?=$savg?> </td>
     <td>&nbsp; </td>
     </tr>

     <tr>
     <td> &nbsp;  </td>
     <td> &nbsp;  </td>
     <td> &nbsp;  </td>
     <td> &nbsp;  </td>
       <td> 총 평균 </td>
     <td><?=$askor?> </td>      <td><?=$aseng?> </td>
     <td><?=$asmath?></td>      <td><?=$ashist?> </td>
     <td><?=$assum?> </td>      <td><?=$asavg?> </td>
     <td>&nbsp; </td>
     </tr>

    </table>

</div>
<br>
</section>

<? include "bottom.php" ?>

º update_ok.php

<?
$servername = "localhost";
$username = "root";
$password = "autoset";
$dbname = "korea";

$conn = new mysqli($servername, $username, $password, $dbname);
?>

<?
 $sno = $_GET['sno'];
 $sname = $_GET['sname'];
 $kor = $_GET['kor'];
 $eng = $_GET['eng'];
 $math = $_GET['math'];
 $hist = $_GET['hist'];
 
 $SQL = "update examtbl set sname='$sname', kor='$kor', eng='$eng', math='$math',hist='$hist'";
 $SQL = $SQL . "where sno= '$sno'";        
 echo $SQL;
 $conn -> query($SQL);
?>

<script>
location.href="list.php";
</script>

 

Comments