일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- sql
- 네트워크관리사
- 라우터
- 이것이 자바다
- Oracle
- VLAN
- javaee
- ospf
- Cisco
- 리눅스
- 데이터베이스
- 오라클
- jsp
- 정처기필기
- 네트워크
- 버추얼머신
- ciscopacket
- rinux
- autoset
- cisco packet
- w3school
- 참조타입
- 원형그래프
- Java
- 정보처리기사
- NCS
- jsp연결
- 자바
- html
- php
- Today
- Total
기록해! 정리해!
AutoSet -- SQL연결 학생 성적처리 ver 11 본문
06/10
º 윈도우 APM
홈 디렉토리 열기
새 메모장에
<h1> Test </h1> 작성
폴더는 C:\AutoSet10\public_html
파일명 : index.php
모든파일 로 저장
127.0.0.1 들어가면
확인할 수 있음
<h1> Test </h1>
<?
$servername = "localhost";
$username = "root";
$password = "world63";
$dbname = "ppk300";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} else {
echo "접속 성공 !!!" ;
}
$SQL="select * from table600 ";
$result = $conn -> query($SQL);
?>
<table border=1 >
<tr><td>번호</td><td>아이디 </td><td>암호 </td></tr>
<?
while ( $row = $result -> fetch_assoc() ){
?>
<tr>
<td>
<a href=del.php?idx=<?=$row["idx"]?>>
<?=$row["idx"]?>
</a>
<td> <?=$row["id"]?></td>
<td><?=$row["pwd"]?> </td>
</tr>
<?
}
$conn -> close();
?>
6/13
웹서버, MySQL 두개 다 떠있는지 확인하기
º phpmyadmin
root
autoset
새 데이터베이스 ppk400
Create table examtbl (
sNo varchar(10) not null primary key ,
sName varchar(20),
kor int,
eng int,
math int,
hist int
);
insert into examtbl values('10101','김학생', 75, 85, 90, 60);
insert into examtbl values('10102','이학생', 70, 75, 70, 60);
insert into examtbl values('10103','박학생', 70, 85, 80, 75);
insert into examtbl values('10201','조학생', 90, 85, 100, 50);
insert into examtbl values('10202','황학생', 65, 65, 60, 70);
insert into examtbl values('10203','임학생', 45, 55, 50, 55);
insert into examtbl values('10304','천학생', 70, 75, 85, 80);
insert into examtbl values('10305','남학생', 100, 85, 90, 90);
insert into examtbl values('10306','여학생', 80, 95, 90, 85);
insert into examtbl values('10307','노학생', 35, 55, 70, 55);
select * from examtbl;
비주얼 스튜디오 코드 다운받기
확장에서 php Debug, format html 설치받기
탐색기에서 autoset10 - publichtml 폴더 연결해주기
마우스 오른쪽키 눌러서 새파일 생성 (list.php)
º 접속하기
w3school
php MySQL insert data
$servername = "localhost";
$username = "root";
$password = "autoset";
$dbname = "ppk400";
//1. 서버 및 데이터베이스 커넥션 명령어
$conn = new mysqli($servername, $username, $password, $dbname);
//2. SQL문 작성하기
$SQL = "select sno, sname, kor, eng, math, hist from examtbl";
//3. SQL문 실행하기
$result = $conn -> query($SQL); --리턴값을 받아서 출력한다
?>
<table border = 1 >
<tr>
<td>학번 </td> <td>이름 </td> <td>국어 </td> <td>영어 </td>
<td>수학 </td><td>역사 </td>
</tr>
<?
//4. while 문에서 컬럼 출력하기
while ( $row = $result -> fetch_assoc() ){ --리턴값
?>
<tr>
<td><?=$row['sno']?></td>
<td><?=$row['sname']?></td>
<td><?=$row['kor']?></td>
<td><?=$row['eng']?></td>
<td><?=$row['math']?></td>
<td><?=$row['hist']?></td>
</tr>
<?
}
?>
$servername = "localhost";
$username = "root";
$password = "autoset";
$dbname = "ppk400";
$conn = new mysqli($servername, $username, $password, $dbname);
$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>
</tr>
<?
while ( $row = $result -> fetch_assoc() ){
$sum = $row['kor'] + $row['eng'] + $row['math'] + $row['hist'];
$avg = $sum / 4 ;
?>
<tr>
<td><?=$row['sno']?></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>
</tr>
<?
}
?>
</table>
º 누적합 구하기
<?
$servername = "localhost";
$username = "root";
$password = "autoset";
$dbname = "ppk400";
$conn = new mysqli($servername, $username, $password, $dbname);
$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>
</tr>
<?
$ksum =0 ;
$esum =0 ;
$msum =0 ;
$hsum =0 ;
while ( $row = $result -> fetch_assoc() ){
$sum = $row['kor'] + $row['eng'] + $row['math'] + $row['hist'];
$avg = $sum / 4 ;
$ksum = $ksum + $row['kor'];
$esum = $esum + $row['eng'];
$msum = $msum + $row['math'];
$hsum = $hsum + $row['hist'];
?>
<tr>
<td><?=$row['sno']?></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>
</tr>
<?
}
?>
<tr> --리턴값을 받는게 아니라서 while문 밖에 씀
<td></td> <td></td>
<td><?=$ksum?></td>
<td><?=$esum?></td>
<td><?=$msum?></td>
<td><?=$hsum?></td>
<td></td> <td></td>
</tr>
</table>
º 누적합계, 누적평균 구하기
<?
$servername = "localhost";
$username = "root";
$password = "autoset";
$dbname = "ppk400";
$conn = new mysqli($servername, $username, $password, $dbname);
$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>
</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 = $sum / 4 ;
$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 = $ksum / $count;
$eavg = $esum / $count;
$mavg = $msum / $count;
$havg = $hsum / $count;
$ssavg = $ssum / $count;
$saavg = $savg / $count;
?>
<tr>
<td><?=$row['sno']?></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>
</tr>
<?
}
?>
<tr>
<td colspan=2> 누적합 </td> -- 칸 합치기, 공백
<td><?=$ksum?></td>
<td><?=$esum?></td>
<td><?=$msum?></td>
<td><?=$hsum?></td>
<td><?=$ssum?></td>
<td><?=$savg?></td>
</tr>
<tr>
<td colspan=2> 누적평균(<?=$count?>) </td>
<td><?=$kavg?></td>
<td><?=$eavg?></td>
<td><?=$mavg?></td>
<td><?=$havg?></td>
<td><?=$ssavg?></td>
<td><?=$saavg?></td>
</tr>
</table>
º 평점 주기
<?
$servername = "localhost";
$username = "root";
$password = "autoset";
$dbname = "ppk400";
$conn = new mysqli($servername, $username, $password, $dbname);
$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>
</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 = $sum / 4 ;
$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 = $ksum / $count;
$eavg = $esum / $count;
$mavg = $msum / $count;
$havg = $hsum / $count;
$ssavg = $ssum / $count;
$saavg = $savg / $count;
if ($avg >= 90 ){
$grade = "A" ;
} else if ($avg >= 80){
$grade = "B" ;
} else if ($avg >= 70){
$grade = "C" ;
} else {
$grade = "F" ;
}
?>
<tr>
<td><?=$row['sno']?></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=2> 누적합 </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=2> 누적평균(<?=$count?>명) </td>
<td><?=$kavg?></td>
<td><?=$eavg?></td>
<td><?=$mavg?></td>
<td><?=$havg?></td>
<td><?=$ssavg?></td>
<td><?=$saavg?></td>
<td></td>
</tr>
</table>
º CSS 테이블 꾸미기
<style>
header{
background-color:blue;
height:50px; --높이
line-height:50px;
font-size:20px; color:#ffffff;
text-align:center; --가운데 정렬
}
nav{
background-color:#6699ff;
height:30px;
line-height:30px;
font-size:13px; color:#ffffff;
}
section{
background-color:#cccccc;
font-size:12px;
min-heigt:500px; --최소 500
}
footer{
background-color:blue;
height:40x;
line-height:20px;
font-size:14px; color:#ffffff;
text-align:center;
}
table{
width:500px; --넓이
}
</style>
<header> 학생 성적처리 Ver 11. </header>
<nav>
   <a href=form.php> 성적저장 </a>
 <a href=list.php> 성적조회 </a>
 <a href=index.php> 홈으로 </a>
</nav>
<section>
<div align=center>
<br>
<h2> 학생 성적 목록 보기 </h2>
<?
$servername = "localhost";
</div>
<br>
</section>
<footer>
<address>
<center>
Home page : http://www.visiongongjang.com <br>
mobile : 010-2222-3333 <br>
</center>
</address>
</footer>
º 순번 추가하기
<tr>
<td>순번 </td>
<td><?=$count?></td>
<td><?=$row['sno']?></td>
.
.
<tr>
<td colspan=3> 누적합 </td>
º F성적 레코드 색상 바꿔보기
$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><?=$row['sno']?></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>
º include 적용하기 (자르기)
새파일 top.php , bottom.php, DBconn.php, form.php, index.php 만들기
top.php
<link href="top.css" rel="stylesheet"
type="text/css" charset="UTF-8" /> --청와대 홈페이지에서 링크 쌔벼옴 ㅋㅋ
<header> 학생 성적처리 Ver 11. </header>
<nav>
   <a href=form.php> 성적저장 </a>
 <a href=list.php> 성적조회 </a>
 <a href=index.php> 홈으로 </a>
</nav>
top.css
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;
}
bottom php.
<footer>
<address>
<center>
Home page : http://www.visiongongjang.com <br>
mobile : 010-2222-3333 <br>
</center>
</address>
</footer>
DBconn.php
<?
$servername = "localhost";
$username = "root";
$password = "autoset";
$dbname = "ppk400";
$conn = new mysqli($servername, $username, $password, $dbname);
?>
index.php
<? include 'top.php' ?>
<? include 'DBconn.php' ?>
<section>
<br>
<div align=center>
<h2> 학생 성적 처리 프로그램 요약 </h2>
</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>학 번 </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
<? 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);
?>
성적조회 들어가서 보면 영심이 들어와있는 거 확인할 수 있음.
소수점자리 정리를 위해서 list.php 수정
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><?=$row['sno']?></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=3> 누적합 </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> 누적평균(<?=$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_ok.php 마지막줄에
<script>
location.href="list.php";
</script>
해주면 바로 넘어감
º 평균을 클릭하면 삭제되게 만들기
list php.
<td><?=$sum?></td>
<td>
<a href="del.php?sno=<?=$row['sno']?>"> <?=$avg?> </a>
</td>
<td><?=$grade?></td>
del.php 새파일 만들어주기
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>
12번 평균을 누르니 삭제된 것을 확인할 수 있음
º 학번 클릭해서 값 수정하기
list php.
<td>
<a href="edit.php?sno=<?=$row['sno']?>" > <?=$row['sno']?> </a>
</td>
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>학 번 </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' ?>
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>
'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 --학생 성적처리 ver 11 코드정리 (0) | 2022.06.13 |