기록해! 정리해!

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

Visual studio (PHP)

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

zsuling 2022. 6. 13. 21:56

2022.06.10 - [Visual studio] - AutoSet -- SQL연결 학생 성적처리 ver 11

 

AutoSet -- SQL연결 학생 성적처리 ver 11

06/10 º 윈도우 APM 홈 디렉토리 열기 새 메모장에 Test 작성 폴더는 C:\AutoSet10\public_html 파일명 : index.php 모든파일 로 저장 127.0.0.1 들어가면 확인할 수 있음  Test <? $servername = "localhos..

apr49.tistory.com

 

 

 

top.php

<link href="top.css" rel="stylesheet"
      type="text/css" charset="UTF-8" /> 
<header> 학생 성적처리 Ver 11. </header>
<nav>
 &emsp;&emsp;&emsp;<a href=form.php> 성적저장 </a>
 &emsp;<a href=list.php> 성적조회 </a>
 &emsp;<a href=index.php> 홈으로  </a>
</nav>

top.css

header{
    background-color:#ADD8E6;
    height:50px;
    line-height:50px;
    font-size:20px; color:#ffffff;
    text-align:center;
    }
    nav{
    background-color:#FFFACD;
    height:30px;
    line-height:30px;
    font-size:13px; color:#ffffff;
    }
    section{
    background-color:#F0FFFF;
    font-size:12px; color:#696969;
    min-heigt:500px;
    }
    footer{
    background-color:#FFFACD;
    height:40x;
    line-height:20px;
    font-size:14px; color:#C0C0C0;
    text-align:center;
    }

DBconn.php

<?
$servername = "localhost";
$username = "root";
$password = "autoset";
$dbname = "ppk400";
$conn = new mysqli($servername, $username, $password, $dbname);
?>

bottom.php

<footer>
<address>
<center>
Home page : http://www.visiongongjang.com <br>
mobile : 010-2222-3333 <br>
</center>
</address>
</footer>

list.php

<? include 'top.php' ?>
<? include 'DBconn.php' ?>

<style>
   table{
      width:600px; 
    }
</style>

<section>
<div align=center>
<br>
<h2> 학생 성적 목록 보기 </h2>
<?

$SQL = "select  sno, sname, kor, eng, math, hist  from examtbl  " ;
$result = $conn -> query($SQL);
?>
<table  border = 1 >
<tr>
    <td>순번 </td>   
    <td>학번 </td> <td>이름 </td> <td>국어 </td> <td>영어 </td>
    <td>수학 </td> <td>역사 </td> <td>합계 </td> <td>평균 </td>
    <td>평점 </td> 
</tr>  
<?

$ksum =0 ;
$esum =0 ;
$msum =0 ;
$hsum =0 ;
$ssum =0 ;
$savg =0 ;
$count =0 ;

while ( $row = $result -> fetch_assoc() ){
    $sum = $row['kor'] + $row['eng'] + $row['math'] + $row['hist'];
    $avg = round($sum / 4,1) ;

    $count = $count + 1 ;

    $ksum = $ksum + $row['kor'];
    $esum = $esum + $row['eng'];
    $msum = $msum + $row['math'];
    $hsum = $hsum + $row['hist'];
    $ssum = $ssum + $sum;
    $savg = $savg + $avg;

    $kavg = round($ksum / $count, 1);
    $eavg = round($esum / $count, 1);
    $mavg = round($msum / $count, 1);
    $havg = round($hsum / $count, 1);
    $ssavg =round( $ssum / $count, 1);
    $saavg = round($savg / $count, 1);

    $bgcolor="#F0FFFF";

    if ($avg >= 90 ){
        $grade = "A" ;
    } else if ($avg >= 80){
        $grade = "B" ;
    } else if ($avg >= 70){
        $grade = "C" ;
    } else {
        $grade = "F" ;
        $bgcolor="#778899";
    }
?>    
<tr bgcolor="<?=$bgcolor?>" >
    <td><?=$count?></td>
     <td>
     <a href="edit.php?sno=<?=$row['sno']?>" > 
        <?=$row['sno']?>
     </a>
     </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>
     <a href="del.php?sno=<?=$row['sno']?>"> 
        <?=$avg?>
     </td>
     <td><?=$grade?></td>
</tr>    
<?  
}
?>
<tr>
    <td colspan=3> &nbsp;누적합 </td>  
    <td><?=$ksum?></td>
    <td><?=$esum?></td>
    <td><?=$msum?></td>
    <td><?=$hsum?></td>
    <td><?=$ssum?></td> 
    <td><?=$savg?></td> 
    <td></td>
</tr>  
<tr>
    <td colspan=3> &nbsp;누적평균(<?=$count?>명) </td>  
    <td><?=$kavg?></td>
    <td><?=$eavg?></td>
    <td><?=$mavg?></td>
    <td><?=$havg?></td>
    <td><?=$ssavg?></td> 
    <td><?=$saavg?></td> 
    <td></td>
</tr>  
</table>
</div>
<br>
</section>
<? include 'bottom.php' ?>

form.php

<? include 'top.php' ?>
<? include 'DBconn.php' ?>

<style>
    table{
    width:300px;
    heigh:300px;
    }
    tr {
        text-align:center;
    }
</style>


<section>
<br>
<div align=center>
<h2> 학생 성적 입력 </h2>


<form action=form_ok.php>
<table border=1 >
<tr><td>학&nbsp;번 </td><td><input type=text name=sno></td></tr>  
<tr><td>성&nbsp;명 </td><td><input type=text name=sname></td></tr>
<tr><td>국&nbsp;어 </td><td><input type=text name=kor></td></tr>
<tr><td>영&nbsp;어 </td><td><input type=text name=eng></td></tr>
<tr><td>수&nbsp;학 </td><td><input type=text name=math></td></tr>
<tr><td>역&nbsp;사 </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

<? include 'DBconn.php' ?>
<?
$sno = $_GET['sno'];
$sname = $_GET['sname'];
$kor = $_GET['kor'];
$eng = $_GET['eng'];
$math = $_GET['math'];
$hist = $_GET['hist'];

$SQL = "insert into examtbl (sno, sname, kor, eng, math, hist)";
$SQL = $SQL . "values ('$sno', '$sname', '$kor', '$eng', '$math', '$hist')";

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

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

index.php

<? include 'top.php' ?>
<? include 'DBconn.php' ?>

<section>
<br>
<div align=center>
<h2> 학생 성적 처리 프로그램 요약 </h2>
</div>
<br>
</section>

<? include 'bottom.php' ?>

edit.php

<? include 'top.php' ?>
<? include 'DBconn.php' ?>
<?
$sno =$_GET['sno'];
$SQL = "select  sno, sname, kor, eng, math, hist 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'];
?>

<style>
    table{
    width:300px;
    heigh:300px;
    }
    tr {
        text-align:center;
    }     
</style>

<section>
<br>
<div align=center>
<h2> 학생 성적 수정 </h2>
<form action=update_ok.php>
<table border=1 >
<tr><td>학&nbsp;번 </td><td><input type=text name=sno value="<?=$sno?>"> </td></tr> 
<tr><td>성&nbsp;명 </td><td><input type=text name=sname value="<?=$sname?>"> </td></tr>
<tr><td>국&nbsp;어 </td><td><input type=text name=kor value="<?=$kor?>"> </td></tr>
<tr><td>영&nbsp;어 </td><td><input type=text name=eng value="<?=$eng?>"> </td></tr>
<tr><td>수&nbsp;학 </td><td><input type=text name=math value="<?=$math?>"> </td></tr>
<tr><td>역&nbsp;사 </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' ?>

update_ok.php

<? include 'DBConn.php'  ?>
<?
$sno =$_GET['sno'];
$sname=$_GET['sname'];
$kor=$_GET['kor'];
$eng=$_GET['eng'];
$math=$_GET['math'];
$hist=$_GET['hist'];

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

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

del.php

<? include 'DBconn.php' ?>
<?
$sno = $_GET['sno'];

$SQL = "delete from examtbl where sno= '$sno' ";
echo $SQL;
$conn->query($SQL);
?>

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

 

form

list

index

 

'Visual studio (PHP)' 카테고리의 다른 글

JAVA Script  (0) 2022.06.16
HTML 메모장  (0) 2022.06.16
html 태그  (0) 2022.06.15
Autoset --테이블 만들기  (0) 2022.06.13
AutoSet -- SQL연결 학생 성적처리 ver 11  (0) 2022.06.10
Comments