Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 네트워크
- 오라클
- 이것이 자바다
- VLAN
- Cisco
- 버추얼머신
- sql
- rinux
- jsp
- 라우터
- ospf
- ciscopacket
- Java
- Oracle
- javaee
- 자바
- 정보처리기사
- 데이터베이스
- 참조타입
- 리눅스
- cisco packet
- 네트워크관리사
- html
- 정처기필기
- NCS
- 원형그래프
- php
- w3school
- autoset
- jsp연결
Archives
- Today
- Total
기록해! 정리해!
HTML --성적조회 프로그램Ver 1.0 (3 , 빅데이터) 코드정리 본문
bigdata
insert.php
<?
for ($i=1 ; $i <= 53 ; $i++ ){
include $_SERVER["DOCUMENT_ROOT"]."/include/DBConn.php" ;
//난수발생기
$randomName = mt_rand(0, 9);
$randomAge = mt_rand(0, 3);
$randomtitle1 = mt_rand(0, 4);
$randomtitle2 = mt_rand(0, 4);
$randometc1 = mt_rand(0, 4);
$randometc2 = mt_rand(0, 4);
$randometc3 = mt_rand(0, 4);
$name = array('하니','똘이','영심이','만수','지효','둘리','하나','둘','셋','넷');
$age = array('12','13','14','15');
$title1 = array('ASP','JSP','PHP','JAVA','C#');
$title2 = array('초급','중급','고급','심화','실무');
$etc = array('산','바다','강','하늘','땅');
//배열적용
$name=$name[$randomName];
$age=$age[$randomAge];
$title=$title1[$randomtitle1]." , ".$title2[$randomtitle2];
$etc= $etc[$randometc1]." , ".$etc[$randometc2]." , ".$etc[$randometc3] ;
$SQL = "insert into board (name, age, title, etc) values ('$name','$age','$title','$etc' )";
//echo $SQL;
$conn -> query($SQL);
$conn -> close();
}
?>
<script>
location.href="list.php" ;
</script>
list.php
<? include $_SERVER["DOCUMENT_ROOT"]."/include/top.php"?>
<? include $_SERVER["DOCUMENT_ROOT"]."/include/DBConn.php" ?>
<?
if($_GET['idx']==""){
$idx=0;
}
else{
$idx=$_GET['idx'];
}
$SQL_tc = "select count(*) tc from board ";
$result_tc = $conn -> query($SQL_tc);
$row_tc = $result_tc -> fetch_assoc() ;
$SQL = "select * from board list order by idx asc limit $idx, 10";
$result = $conn -> query($SQL);
$total_page = ceil($row_tc['tc'] / 10) ;
$now_page = ($idx / 10) +1 ;
?>
<style>
table{
width:500px;
}
td{
text-align:center;
height:25px;
}
</style>
<section>
<br>
<div id=section1>
<b>빅데이터 목록 조회</b> <br>
</div>
<br>
<div align=center>
전체 레코드 수 : <?=$row_tc['tc']?> <br>
페이지 수 : <?=$total_page?>   현재 페이지 : <?=$now_page?>
<table border=1>
<tr>
<td>순번</td><td>이름</td><td>나이</td>
<td>제목</td><td>특이사항</td>
</tr>
<? while( $row = $result -> fetch_assoc() ){
$s_kor=$s_kor+$row['kor'];
$s_eng=$s_eng+$row['eng'];
$s_math=$s_math+$row['math'];
$s_hist=$s_hist+$row['hist'];
$s_ssum=$s_ssum+$row['ssum'];
$s_savg=$s_savg+$row['savg'];
?>
<tr>
<td><?=$row['idx']?></td>
<td><?=$row['name']?></td>
<td><?=$row['age']?></td>
<td><?=$row['title']?></td>
<td><?=$row['etc']?></td>
</tr>
<? } ?>
</table>
<a href=list.php?idx?idx=0> 처음으로 </a>  
<? if($idx == 0){ ?>
이전  
<?}else{?>
<a href=list.php?idx=<?=$idx-10?>> 이전 </a>  
<?}?>
<? if($now_page == $total_page ){ ?>
다음  
<? } else { ?>
<a href=list.php?idx=<?=$idx+10?>> 다음 </a>  
<? } ?>
<? $end_page = ($total_page - 1) * 10 ; ?>
<a href=list.php?idx=<?=$end_page?>> 마지막으로 </a>
<br>
</div>
</section>
<? include $_SERVER["DOCUMENT_ROOT"]."/include/bottom.php"?>
include
bottom.php
<footer>
HRDKOREA Copyrightⓒ2018 ALL rights reserved. Human Resources Development Services of Korea
</footer>
</div>
</body>
</html>
DBconn.php
<?
$host=$_SERVER['HTTP_HOST'];
$path="http://".$host;
$conn = new mysqli("localhost","root","autoset","korea");
?>
top.php
<?
$host=$_SERVER['HTTP_HOST'];
$path="http://".$host;
// echo $path;
// echo "<br>" ;
// echo $_SERVER["DOCUMENT_ROOT"];
?>
<html>
<head>
<title> 정보처리기능사 연습 </title>
<style>
header{
background-color:blue;
height:80px;
line-height:80px;
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:650px;
}
footer{
background-color:#0033ff;
height: 40px;
line-height:40px;
color:#ffffff;
text-align:center;
font-size: 17px;
}
#section1{
text-align:center;
font-size:25px;
}
#body{
width:80%;
margin:auto;
}
</style>
</head>
<body>
<div id="body">
<header> (과정평가형 정보처리기능사)성적조회 프로그램 Ver1.0 </header>
<nav>
  <a href='<?=$path?>/jungbo/form.php'>성적입력</a>
 <a href='<?=$path?>/jungbo/list.php'>성적조회</a>
 <a href='<?=$path?>/member/member.php'>회원가입</a>
 <a href='<?=$path?>/member/member_list.php'>회원조회</a>
 <a href='<?=$path?>/join/join_list.php'>테이블조인</a>
 <a href='<?=$path?>/school/form.php'>학생등록</a>
 <a href='<?=$path?>/school/form_list.php'>학생목록</a>
 <a href='<?=$path?>/bigdata/insert.php'>빅데이터생성</a>
 <a href='<?=$path?>/bigdata/list.php'>빅데이터목록보기</a>
 <a href='<?=$path?>/index.php'>홈으로</a>
</nav>
join_list.php
<? include $_SERVER["DOCUMENT_ROOT"]."/include/top.php"?>
<? include $_SERVER["DOCUMENT_ROOT"]."/include/DBconn.php" ?>
<?
$ch1 = $_GET['ch1'];
$ch2 = $_GET['ch2'];
$SQL = " select e.sno, sname, kor, eng, math, hist , img, " ;
$SQL = $SQL . " kor+eng+math+hist as ssum, " ;
$SQL = $SQL . " round((kor+eng+math+hist)/4,1) as savg from examtbl e left join member m on e.sno=m.sno " ;
if( $ch1 == "" ){
$SQL = $SQL . " order by e.sno desc " ;
}else if( $ch1 == "sno"){
$SQL = $SQL . " where e.sno like '%$ch2%' order by e.sno desc " ;
}else if( $ch1 == "sname"){
$SQL = $SQL . " where sname like '%$ch2%' order by e.sno desc " ;
}else if( $ch1 == "kor"){
$SQL = $SQL . " where kor like '%$ch2%' order by e.sno desc " ;
}
$result = $conn -> query($SQL);
?>
<style>
table{
width:500px;
}
td{
text-align:center;
height:25px;
}
</style>
<section>
<br>
<div id="section1">
성적조회목록 <br>
</div>
<br>
<div align=center>
<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>
<?
$i =0;
$s_kor=0; $s_eng=0; $s_math=0; $s_hist=0;
$s_sum=0; $s_avg=0;
while ($row = $result -> fetch_assoc()) {?>
<?
if ($row['savg']>=90){
$grade = 'A';
}else if ($row['savg']>=80){
$grade = 'B';
}else if($row['savg']>=70){
$grade = 'C';
}else{
$grade = 'F';
}
$i = $i + 1 ;
$s_kor=$s_kor+$row['kor'];
$s_eng=$s_eng+$row['eng'];
$s_math=$s_math+$row['math'];
$s_hist=$s_hist+$row['hist'];
$s_sum=$s_sum+$row['ssum'];
$s_avg=$s_avg+$row['savg'];
if ($row['img'] == null){
$img= 'space.png';
}else{
$img= $row['img'];
}
?>
<tr>
<td><img src="<?=$path?>./img/<?=$img?>" width=30 height=30></td>
<td><a href=<?=$path?>/member/member.php?sno=<?=$row['sno']?>><?=$row['sno']?></td></a>
<td>
<a href=<?=$path?>/jungbo/edit.php?sno=<?=$row['sno']?>&ch1=<?=$ch1?>&ch2=<?=$ch2?>>
<?=$row['sname']?></a></td>
<td><?=$row['kor']?></td>
<td><?=$row['eng']?></td>
<td><?=$row['math']?></td>
<td><?=$row['hist']?></td>
<td><?=$row['ssum']?></td>
<td><?=$row['savg']?></td>
<td><?=$grade?></td>
</tr>
<?}?>
<tr>
<td> </td>
<td></td> <td> 총점 </td>
<td><?=$s_kor?> </td> <td><?=$s_eng?> </td>
<td><?=$s_math?></td> <td><?=$s_hist?> </td>
<td><?=$s_sum?> </td> <td><?=$s_avg?> </td>
<td></td>
</tr>
<tr>
<td> </td>
<td></td> <td> 평균 (<?=$i?>명) </td>
<td><?=round($s_kor / $i, 1)?> </td> <td><?=round($s_eng / $i, 1)?> </td>
<td><?=round($s_math / $i, 1)?></td> <td><?=round($s_hist / $i, 1)?> </td>
<td><?=round($s_sum / $i, 1)?> </td> <td><?=round($s_avg / $i, 1)?> </td>
<td></td>
</tr>
</table>
<form>
<select name=ch1>
<option value="sno">학번</option>
<option value="sname">이름</option>
<option value="kor">국어점수</option>
</select>
<input type=text name=ch2>
<input type=submit value="검색하기">
</form>
<br>
</div>
</section>
<? include $_SERVER["DOCUMENT_ROOT"]."/include/bottom.php"?>
jungbo
delete.php
<? include $_SERVER["DOCUMENT_ROOT"]."DBConn.php" ?>
<?
$sno = $_GET['sno'];
$ch1 = $_GET['ch1'];
$ch2 = $_GET['ch2'];
$SQL ="delete from examtbl where sno ='$sno' " ;
$conn -> query($SQL);
?>
<script>
location.href="list.php?ch1=<?=$ch1?>&ch2=<?=$ch2?>" ;
</script>
edit.php
<? include $_SERVER["DOCUMENT_ROOT"]."/include/top.php" ?>
<? include $_SERVER["DOCUMENT_ROOT"]."/include/DBConn.php" ?>
<?
$sno=$_GET['sno'];
$ch1=$_GET['ch1'];
$ch2=$_GET['ch2'];
$SQL = " select * from examtbl where sno=$sno ";
$result = $conn -> query($SQL);
$row = $result ->fetch_assoc();
?>
<style>
table{
width: 350px ;
height:300px ;
}
td{
text-align:center;
}
</style>
<script>
function ck1(){
if (f1.sno.value == "") {
alert("학번을 입력해 주세요");
f1.sno.focus();
return false;
}else{
alert("학생 성적이 입력 되었습니다.");
}
}
function ck2(sno, ch1, ch2){
location.href="delete.php?sno="+sno+"&ch1="+ch1+"&ch2="+ch2;
}
</script>
<section>
<br><br>
<div id=section1>
학생성적수정하기
</div>
<br>
<div align=center>
<form name=f1 action=update_ok.php onSubmit="return ck1()" method=get >
<input type=hidden name=ch1 value="<?=$ch1?>" >
<input type=hidden name=ch2 value="<?=$ch2?>" >
<table border=1>
<tr><td>학 번</td><td><input type=text name=sno value="<?=$row['sno']?>" > </td></tr>
<tr><td>이 름</td><td> <input type=text name=sname value="<?=$row['sname']?>" ></td></tr>
<tr><td>국 어</td><td> <input type=text name=kor value="<?=$row['kor']?>" ></td></tr>
<tr><td>영 어</td><td> <input type=text name=eng value="<?=$row['eng']?>" ></td></tr>
<tr><td>수 학</td><td> <input type=text name=math value="<?=$row['math']?>" ></td></tr>
<tr><td>역 사</td><td> <input type=text name=hist value="<?=$row['hist']?>" ></td></tr>
<tr><td colspan=2 align=center><input type=submit value="수정하기" >
<input type=button value="삭제하기" onClick="ck2('<?=$sno?>','<?=$ch1?>','<?=$ch2?>')" >
</td></tr>
</table>
</form>
</div>
</section>
<? include $_SERVER["DOCUMENT_ROOT"]."/include/bottom.php" ?>
form_ok.php
<? include $_SERVER["DOCUMENT_ROOT"]."/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>
form.php
<? include $_SERVER["DOCUMENT_ROOT"]."/include/top.php"?>
<style>
table{
width:350px;
height: 300px;
}
td{
text-align:center;
}
</style>
<script>
function ck1(){
if(f1.sno.value == ""){
alert("학번을 입력해 주세요");
f1.sno.focus();
return false;
}else{
alert("학생 성적이 입력 되었습니다.");
}
}
</script>
<section>
<br><br>
<div id="section1">
학생 성적 입력 <br>
</div>
<br>
<div align=center>
<form name=f1 action=form_ok.php onSubmit="return ck1()" method=get>
<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>
</section>
<? include $_SERVER["DOCUMENT_ROOT"]."/include/bottom.php"?>
list.php
<? include $_SERVER["DOCUMENT_ROOT"]."/include/top.php"?>
<? include $_SERVER["DOCUMENT_ROOT"]."/include/DBconn.php" ?>
<?
$ch1=""; $ch2="";
$ch1 = $_GET['ch1'];
$ch2 = $_GET['ch2'];
$SQL = " select sno, sname, kor, eng, math, hist , " ;
$SQL = $SQL . " kor+eng+math+hist as ssum, " ;
$SQL = $SQL . " round((kor+eng+math+hist)/4,1) as savg from examtbl " ;
if( $ch1 == "" ){
$SQL = $SQL . " order by sno desc " ;
}else if( $ch1 == "sno"){
$SQL = $SQL . " where sno like '%$ch2%' order by sno desc " ;
}else if( $ch1 == "sname"){
$SQL = $SQL . " where sname like '%$ch2%' order by sno desc " ;
}else if( $ch1 == "kor"){
$SQL = $SQL . " where kor like '%$ch2%' order by sno desc " ;
}
$result = $conn -> query($SQL);
?>
<style>
table{
width:500px;
}
td{
text-align:center;
height:25px;
}
</style>
<section>
<br>
<div id="section1">
성적조회목록 <br>
</div>
<br>
<div align=center>
<table border=1>
<tr><td>학번</td> <td>이름</td> <td>국어</td>
<td>영어</td> <td>수학</td> <td>역사</td>
<td>합계</td> <td>평균</td> <td>평점</td>
</tr>
<?
$i =0;
$s_kor=0; $s_eng=0; $s_math=0; $s_hist=0;
$s_sum=0; $s_avg=0;
while ($row = $result -> fetch_assoc()) {?>
<?
if ($row['savg']>=90){
$grade = 'A';
}else if ($row['savg']>=80){
$grade = 'B';
}else if($row['savg']>=70){
$grade = 'C';
}else{
$grade = 'F';
}
$i = $i + 1 ;
$s_kor=$s_kor+$row['kor'];
$s_eng=$s_eng+$row['eng'];
$s_math=$s_math+$row['math'];
$s_hist=$s_hist+$row['hist'];
$s_sum=$s_sum+$row['ssum'];
$s_avg=$s_avg+$row['savg'];
?>
<tr>
<td><?=$row['sno']?></td>
<td>
<a href=edit.php?sno=<?=$row['sno']?>&ch1=<?=$ch1?>&ch2=<?=$ch2?>>
<?=$row['sname']?></a></td>
<td><?=$row['kor']?></td>
<td><?=$row['eng']?></td>
<td><?=$row['math']?></td>
<td><?=$row['hist']?></td>
<td><?=$row['ssum']?></td>
<td><?=$row['savg']?></td>
<td><?=$grade?></td>
</tr>
<?}?>
<tr>
<td> </td>
<td> 총점 </td>
<td><?=$s_kor?> </td> <td><?=$s_eng?> </td>
<td><?=$s_math?></td> <td><?=$s_hist?> </td>
<td><?=$s_sum?> </td> <td><?=$s_avg?> </td>
<td></td>
</tr>
<tr>
<td> </td>
<td> 평균 (<?=$i?>명) </td>
<td><?=round($s_kor / $i, 1)?> </td> <td><?=round($s_eng / $i, 1)?> </td>
<td><?=round($s_math / $i, 1)?></td> <td><?=round($s_hist / $i, 1)?> </td>
<td><?=round($s_sum / $i, 1)?> </td> <td><?=round($s_avg / $i, 1)?> </td>
<td></td>
</tr>
</table>
<form>
<select name=ch1>
<option value="sno">학번</option>
<option value="sname">이름</option>
<option value="kor">국어점수</option>
</select>
<input type=text name=ch2>
<input type=submit value="검색하기">
</form>
</div>
</section>
<? include $_SERVER["DOCUMENT_ROOT"]."/include/bottom.php"?>
update_ok.php
<? include $_SERVER["DOCUMENT_ROOT"]."/include/DBconn.php" ?>
<?
$ch1 = $_GET['ch1'];
$ch2 = $_GET['ch2'];
$sno = $_GET['sno'];
$sname = $_GET['sname'];
$kor = $_GET['kor'];
$eng = $_GET['eng'];
$math = $_GET['math'];
$hist = $_GET['hist'];
$SQL = "update examtbl set sno='$sno',
kor='$kor', eng='$eng',
math='$math', hist='$hist' " ;
$SQL = $SQL . "where sno='$sno'" ;
$conn -> query($SQL);
?>
<script>
location.href="list.php?&ch1=<?=$ch1?>&ch2=<?=$ch2?>" ;
</script>
member
member_delete.php
<? include $_SERVER["DOCUMENT_ROOT"]."/include/DBConn.php" ?>
<?
$sno = $_GET['sno'];
$SQL = "select * from member where sno='$sno'";
$result = $conn -> query($SQL);
$row = $result -> fetch_assoc();
$img = $row['img'];
if ($img != 'space.png' ){
unlink("./img/$img");
}
$SQL ="delete from member where sno ='$sno' " ;
$conn -> query($SQL);
?>
<script>
location.href="member_list.php" ;
</script>
member_edit.php
<? include $_SERVER["DOCUMENT_ROOT"]."/include/top.php"?>
<? include $_SERVER["DOCUMENT_ROOT"]."/include/DBConn.php"?>
<?
$sno=$_GET['sno'];
$SQL= "select * from member where sno='$sno'";
$result= $conn-> query($SQL);
$row=$result->fetch_assoc();
$sno= $row['sno'];
$addr= $row['addr'];
$img= $row['img'];
?>
<style>
table{
width:350px;
height:250px;
}
td{
text-align:center;
}
</style>
<script>
function ck1(){
if(f1.sno.value==""){
alert("학번을 입력해주세요");
f1.sno.focus();
return false;
} else{
alert("학생 성적이 정상적으로 입력되었습니다");
}
}
function ck2(sno){
alert("확인 : " + sno);
location.href="member_delete.php?sno="+sno;
}
</script>
<section>
<br><br><div id=section1><b>학생 정보 수정하기</b></div>
<br>
<div align=center>
<form name="f1" action="member_update.php" onSubmit="return ck1()"
method="post"
enctype="multipart/form-data">
<table border=1>
<input type=hidden name=oldimg value=<?=$img?>>
<tr><td colspan=2 align=center width=400 height=150><img src=<?=$path?>/img/<?=$img?>></td></tr>
<tr><td width=100>학번</td><td><input type=text name=sno value="<?=$sno?>"></td></tr>
<tr><td>주소</td><td><input type=text name=addr value="<?=$addr?>"></td></tr>
<tr><td>사진</td><td><input type=file name=img></td></tr>
<tr><td colspan=2 align=center>
<input type=submit value="수정하기">
<input type=button value="삭제하기" onClick="ck2('<?=$sno?>')">
</table>
</form>
</div>
<br>
</section>
<? include $_SERVER["DOCUMENT_ROOT"]."/include/bottom.php"?>
member_list.php
<? include $_SERVER["DOCUMENT_ROOT"]."/include/top.php" ?>
<? include $_SERVER["DOCUMENT_ROOT"]."/include/DBConn.php" ?>
<?
// 상위 5개의 레코드 나타내기
$SQL = "select * from member order by sno desc limit 0, 5" ;
$result = $conn -> query($SQL);
// 회원수 별칭잡아서 나타내기
$SQLCount = "select count(*) as tc from member " ;
$resultCount = $conn -> query($SQLCount);
$rowCount = $resultCount ->fetch_assoc();
?>
<style>
table{
width: 500px ;
}
td{
text-align:center;
height: 25px ;
}
</style>
<section>
<br>
<div id=section1>
회원 조회 목록 (<?=$rowCount['tc']?> : 명)
</div>
<br>
<div align=center>
<table border=1>
<tr> <td>학번</td> <td>주소</td><td>파일명</td><td>사진</td>
</tr>
<?
while( $row = $result ->fetch_assoc() ) {
?>
<tr> <td><?=$row['sno']?></td>
<td>
<a href=member_edit.php?sno=<?=$row['sno']?>>
<?=$row['addr']?>
</a>
</td>
<td><?=$row['img']?> </td>
<td><img src=<?=$path?>/img/<?=$row['img']?> width=50 height=50> </td>
</tr>
<? } ?>
</table>
<br>
</div>
</section>
<? include $_SERVER["DOCUMENT_ROOT"]."/include/bottom.php" ?>
member_ok.php
<? include $_SERVER["DOCUMENT_ROOT"]."/include/DBConn.php" ?>
<?
$sno=$_POST['sno'];
$addr=$_POST['postcode'] . ":" . $_POST['roadAddress'] . ":" . $_POST['detailAddress'] . ":" . $_POST['detailAddress'];
$mfile=$_FILES['img']['name']; // 파일명 ( 코난.png )
$tmp=$_FILES['img']['tmp_name'];
if ( $mfile =="" ){
$mfile = 'space.png';
} else {
if (file_exists("$path/img/$mfile")) {
// 파일의 이름 구하기
$f_fname = basename($mfile,strrchr($mfile,'.'));
// 시간 가져오기 (시분초)
$time = date("His", time());
// 확장자 가져오기
$ext = strrchr($mfile,'.') ;
$mfile = $f_fname."_".$time.$ext ;
move_uploaded_file($tmp, "$path/img/$mfile");
}else{
move_uploaded_file($tmp, "$path/img/$mfile");
}
}
$SQL ="insert into member(sno,addr,img) values('$sno','$addr','$mfile')" ;
$conn -> query( $SQL);
?>
<script>
location.href="member_list.php" ;
</script>
memeber_update.php
<? include $_SERVER["DOCUMENT_ROOT"]."/include/DBconn.php"?>
<?
$sno=$_POST['sno'];
$addr=$_POST['addr'];
$oldimg=$_POST['oldimg'];
$mfile=$_FILES['img']['name'];
$tmp=$_FILES['img']['tmp_name'];
$SQL = "select * from member where sno='$sno'";
$result = $conn -> query($SQL);
$row = $result -> fetch_assoc();
$img = $row['img'];
if($mfile==""){
//1
//파일 첨부가 없을 때 실행
$SQL = "update member set addr='$addr', img='$mfile' where sno='$sno'";
$conn -> query($SQL);
}
else{
//2
//파일 첨부가 있으면 실행
if($oldimg=="space.png"){
if(file_exists("./img/$mfile")){
//2-1
//기존에 파일이 존재하면 실행
$f_fname = basename($mfile,strrchr($mfile,'.'));
$time = date("His",time());
$ext = strrchr($mfile,'.');
$mfile= $f_fname."_".$time.$ext;
move_uploaded_file($tmp, "./img/$mfile");
$SQL = "update member set addr='$addr', img='$mfile' where sno='$sno'";
$conn -> query($SQL);
}
else{
move_uploaded_file($tmp, "./img/$mfile");
$SQL = "update member set addr='$addr', img='$mfile' where sno='$sno'";
$conn -> query($SQL);
}
}
else{
//2-2
//기존에 파일이 존재하지 않으면 실행
if($img != 'space.png'){
unlink("./img/$img");
}
if(file_exists("./img/$mfile")){
$f_fname = basename($mfile,strrchr($mfile,'.'));
$time = date("His",time());
$ext = strrchr($mfile,'.');
$mfile= $f_fname."_".$time.$ext;
move_uploaded_file($tmp, "./img/$mfile");
$SQL = "update member set addr='$addr', img='$mfile' where sno='$sno'";
$conn -> query($SQL);
}
else{
move_uploaded_file($tmp, "./img/$mfile");
$SQL = "update member set addr='$addr', img='$mfile' where sno='$sno'";
$conn -> query($SQL);
}
}
}
?>
<script>
location.href="member_list.php" ;
</script>
member.php
<? include $_SERVER["DOCUMENT_ROOT"]."/include/top.php" ?>
<?
$sno=$_GET['sno'];
?>
<style>
table{
width: 400px ;
height:250px ;
}
.td1{
text-align:center;
}
</style>
<script>
function ck1(){
if (f1.sno.value == "") {
alert("학번을 입력해 주세요");
f1.sno.focus();
return false;
}else{
alert("학생 성적이 입력 되었습니다.");
}
}
</script>
<script src="//t1.daumcdn.net/mapjsapi/bundle/postcode/prod/postcode.v2.js"></script>
<script>
//본 예제에서는 도로명 주소 표기 방식에 대한 법령에 따라, 내려오는 데이터를 조합하여 올바른 주소를 구성하는 방법을 설명합니다.
function sample4_execDaumPostcode() {
new daum.Postcode({
oncomplete: function(data) {
// 팝업에서 검색결과 항목을 클릭했을때 실행할 코드를 작성하는 부분.
// 도로명 주소의 노출 규칙에 따라 주소를 표시한다.
// 내려오는 변수가 값이 없는 경우엔 공백('')값을 가지므로, 이를 참고하여 분기 한다.
var roadAddr = data.roadAddress; // 도로명 주소 변수
var extraRoadAddr = ''; // 참고 항목 변수
// 법정동명이 있을 경우 추가한다. (법정리는 제외)
// 법정동의 경우 마지막 문자가 "동/로/가"로 끝난다.
if(data.bname !== '' && /[동|로|가]$/g.test(data.bname)){
extraRoadAddr += data.bname;
}
// 건물명이 있고, 공동주택일 경우 추가한다.
if(data.buildingName !== '' && data.apartment === 'Y'){
extraRoadAddr += (extraRoadAddr !== '' ? ', ' + data.buildingName : data.buildingName);
}
// 표시할 참고항목이 있을 경우, 괄호까지 추가한 최종 문자열을 만든다.
if(extraRoadAddr !== ''){
extraRoadAddr = ' (' + extraRoadAddr + ')';
}
// 우편번호와 주소 정보를 해당 필드에 넣는다.
document.getElementById('sample4_postcode').value = data.zonecode;
document.getElementById("sample4_roadAddress").value = roadAddr;
document.getElementById("sample4_jibunAddress").value = data.jibunAddress;
// 참고항목 문자열이 있을 경우 해당 필드에 넣는다.
if(roadAddr !== ''){
document.getElementById("sample4_extraAddress").value = extraRoadAddr;
} else {
document.getElementById("sample4_extraAddress").value = '';
}
var guideTextBox = document.getElementById("guide");
// 사용자가 '선택 안함'을 클릭한 경우, 예상 주소라는 표시를 해준다.
if(data.autoRoadAddress) {
var expRoadAddr = data.autoRoadAddress + extraRoadAddr;
guideTextBox.innerHTML = '(예상 도로명 주소 : ' + expRoadAddr + ')';
guideTextBox.style.display = 'block';
} else if(data.autoJibunAddress) {
var expJibunAddr = data.autoJibunAddress;
guideTextBox.innerHTML = '(예상 지번 주소 : ' + expJibunAddr + ')';
guideTextBox.style.display = 'block';
} else {
guideTextBox.innerHTML = '';
guideTextBox.style.display = 'none';
}
}
}).open();
}
</script>
<section>
<br><br>
<div id=section1>
학생 정보 입력
</div>
<br>
<div align=center>
<form name=f1 action="member_ok.php" onSubmit="return ck1()"
method="post"
enctype="multipart/form-data">
<table border=1>
<tr><td width=100 class="td1">학번</td><td><input type=text name=sno value="<?=$sno?>" ></td></tr>
<tr><td class="td1" >주소 </td><td>
<input type="text" name="postcode" id="sample4_postcode" placeholder="우편번호">
<input type="button" onclick="sample4_execDaumPostcode()" value="우편번호 찾기"><br>
<input type="text" name="roadAddress" id="sample4_roadAddress" placeholder="도로명주소">
<input type="hidden" id="sample4_jibunAddress" placeholder="지번주소">
<span id="guide" style="color:#999;display:none"></span>
<input type="text"name="detailAddress" d="sample4_detailAddress" placeholder="상세주소">
<input type="text"name="detailAddress" id="sample4_extraAddress" placeholder="참고항목">
</td></tr>
<tr><td class="td1">사진</td><td align=center><input type=file name=img ></td></tr>
<tr><td colspan=2 align=center><input type=submit value="저 장 하 기" ></td></tr>
</table>
</form>
</div>
</section>
<? include $_SERVER["DOCUMENT_ROOT"]."/include/bottom.php" ?>
oldmember_ok.php
<? include $_SERVER["DOCUMENT_ROOT"]."/include/DBConn.php" ?>
<?
$sno = $_REQUEST['sno'];
$addr = $_REQUEST['addr'];
$mfile = $_FILES['img']['name'];
$tmp = $_FILES['img']['tmp_name'];
if ( $mfile =="") {
$mfile='space.jpg' ;
} else {
if(file_exists("./img/$mfile")) {
$f_fname = basename($mfile, strrchr($mfile,"."));
$randomNum = date("His",time());
$fileinfo = pathinfo($mfile);
$ext = $fileinfo['extension'];
$mfile = $f_fname."_".$randomNum.".".$ext;
move_uploaded_file($tmp, "./img/$mfile");
} else{
move_uploaded_file($tmp, "./img/$mfile");
}
}
$SQL ="insert into member (sno, addr, img) " ;
$SQL = $SQL . " values ('$sno','$addr' ,'$mfile')" ;
$conn -> query($SQL);
$conn -> close();
echo $SQL;
?>
<script>
// location.href="list.php" ;
</script>
school
form.php
<? include $_SERVER["DOCUMENT_ROOT"]."/include/top.php" ?>
<?
$sno=$_GET['sno'];
?>
<style>
table{
width: 450px ;
height:250px ;
}
.td1{
text-align:center;
}
</style>
<script>
function ck1(){
if (f1.name.value == "") {
alert("이름을 입력해 주세요");
f1.name.focus();
return false;
}else{
alert("입력 되었습니다.");
}
}
</script>
<section>
<br><br>
<div id=section1>
학생 정보 수집
</div>
<br>
<div align=center>
<form name=f1 action="form_ok.php" onSubmit="return ck1()"
method="post"
enctype="multipart/form-data">
<table border=1>
<tr><td width=100 class="td1">이름</td>
<td> <input type=text name=name> </td></tr>
<tr><td class="td1">특이<br>사항</td><td>
<textarea cols=40 rows=5 name=etc> </textarea>
</td></tr>
<tr><td class="td1" >사진 </td>
<td align=center><input type=file name=file >
</td></tr>
<tr><td colspan=2 align=center>
<input type=submit value="저장하기" >
<input type=reset value="다시작성" >
</td></tr>
</table>
</form>
</div>
</section>
<? include $_SERVER["DOCUMENT_ROOT"]."/include/bottom.php" ?>
form_ok.php
<? include $_SERVER["DOCUMENT_ROOT"]."/include/DBConn.php" ?>
<?
$name = $_REQUEST['name'];
$etc = $_POST['etc'];
$mfile = $_FILES['file']['name'];
$tmp = $_FILES['file']['tmp_name'];
if($mfile == ""){
$mfile == "space.png";
}else{
if(file_exists("./files/$mfile")){
$f_fname = basename($mfile,strrchr($mfile,'.'));
$time = date("His", time());
$ext = strrchr($mfile,'.') ;
$mfile = $f_fname."_".$time.$ext ;
move_uploaded_file($tmp, "./files/$mfile");
}else{
move_uploaded_file($tmp, "./files/$mfile");
}
}
$SQL = "insert into school (name, etc, file) values ('$name', '$etc', '$mfile')";
$conn -> query( $SQL);
?>
<script>
location.href="form_list.php" ;
</script>
form_list.php
<? include $_SERVER["DOCUMENT_ROOT"]."/include/top.php" ?>
<? include $_SERVER["DOCUMENT_ROOT"]."/include/DBConn.php" ?>
<?
$ch1 = $_GET['ch1'];
$ch2 = $_GET['ch2'];
$SQL = "select * from school " ;
$SQLEnd = " order by idx desc ";
if( $ch1 == "" ){
$SQL = $SQL . $SQLEnd ;
}else if( $ch1 == "idx"){
$SQL = $SQL . " where idx like '%$ch2%' " . $SQLEnd ;
}else if( $ch1 == "name"){
$SQL = $SQL . " where name like '%$ch2%' " . $SQLEnd ;
}
$result = $conn -> query($SQL);
?>
<style>
table{
width: 650px ;
}
td{
text-align:center;
height: 25px ;
}
</style>
<section>
<br>
<div id=section1>
학생 목록 조회
</div>
<br>
<div align=center>
<table border=1>
<tr> <td>순번</td> <td>이름</td> <td>파일명</td> <td>사진</td>
</tr>
<?
while( $row = $result ->fetch_assoc() ) {
?>
<tr> <td><?=$row['idx']?></td>
<td><?=$row['name']?></td>
<td><?=$row['file']?></td>
<td><a href=form_delete.php?idx=<?=$row['idx']?>>
<img src =./files/<?=$row['file']?> width=30 height=30 > </a></td>
</tr>
<? } ?>
</table>
<form >
<select name=ch1>
<option value="idx">순번</option>
<option value="name">이름</option>
</select>
<input type=text name=ch2>
<input type=submit value="검색하기">
</form>
<br>
</div>
</section>
<? include $_SERVER["DOCUMENT_ROOT"]."/include/bottom.php" ?>
form_delete.php
<? include $_SERVER["DOCUMENT_ROOT"]."/include/DBConn.php" ?>
<?
$idx = $_GET['idx'];
$SQL = "select * from school where idx='$idx'";
$result = $conn -> query($SQL);
$row = $result -> fetch_assoc();
$file = $row['file'];
if ($row['file'] != "space.png" ){
unlink("./files/$file");
}
$SQL ="delete from school where idx ='$idx' " ;
$conn -> query($SQL);
?>
<script>
location.href="form_list.php" ;
</script>
index.php
<? include $_SERVER["DOCUMENT_ROOT"]."/include/top.php"?>
<section>
<br>
<div id="section1">
고등학교 성적 조회 프로그램 <br>
</div>
<br>
 <b>고등학교 성적을 조회하는 프로그램을 작성한다.</b>
<ol>
<li> 학생 성적 정보 테이블을 생성한다. <br>
<li> 학생 성적 테이블에 샘플데이터를 SQL문을 이용하여 추가한다. <br>
<li> 주어진 화면 디자인을 이용하여 화면을 디자인한다. <br>
<li> 업무 여건에 따라 프로그램을 작성한다. <br>
</ol>
</section>
<? include $_SERVER["DOCUMENT_ROOT"]."/include/bottom.php"?>
'Visual studio (PHP)' 카테고리의 다른 글
HTML -- 성적조회프로그램 Ver1.0 (4) 코드정리 (0) | 2022.06.28 |
---|---|
HTML -- 성적조회프로그램 Ver1.0 (4) (0) | 2022.06.23 |
HTML --성적조회 프로그램Ver 1.0 (3 , 빅데이터) (0) | 2022.06.22 |
HTML --성적조회 프로그램Ver 1.0 (2) 코드정리 (0) | 2022.06.22 |
HTML --성적조회 프로그램Ver 1.0 (2) (0) | 2022.06.21 |
Comments