본문 바로가기

비주얼스튜디오코드

[ 27일차 ] 페이지나누기 후 쿠키, 세션을 가지고 로그인하기(관리자모드)

247 DocumentRoot "C:/AutoSet10/public_html"

281 DirectoryIndex index.html index.htm index.php index.php3 -> 우선순위

index.html 이 우선순위 가장 높음

*확장자는 php로 만들때 php,html 둘 다 쓸수있다  ---기존 테이블에서 새로 추가 되는 부분 

<nav>
        &emsp;&emsp;&emsp;
        <a href=#>학생등록</a>&nbsp;
        <a href=#>학생목록/수정</a>&emsp;&emsp;
        <a href=#>빅데이터추가</a>&nbsp;
        <a href=#>페이지나누기1</a>&nbsp;
        <a href=#>페이지나누기2</a>&emsp;&emsp;
        <a href=#>로그인</a>&nbsp;
        <a href=#>로그아웃</a>&emsp;
        <a href=index.php>홈으로</a>
</nav>
index.php



<html>
<head>
<style>
header{
background-color:lightpink;
height:65px;
line-height:65px;
color:white;
font-size:30px;
text-align:center;
}
nav{
    background-color:hotpink;
    height:30px;
    line-height:30px;
    color:white;
    font-size:13px;
}
section{
    background-color:beige;
    min-height:530px;
    font-size:px;
}
footer{
    background-color:lightpink;
    height:40px;
    line-height:40px;
    color:white;
    font-size:15px;
    text-align:center;
}
#body{
width:90%;
margin:auto;
}

/*링크 라인 빼기*/
a{text-decoration-line:none;}

/*링크 라인 빼기& 글씨색 하얀색*/
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>&nbsp;
        <a href=#>학생목록/수정</a>&emsp;&emsp;
        <a href=#>빅데이터추가</a>&nbsp;
        <a href=#>페이지나누기1</a>&nbsp;
        <a href=#>페이지나누기2</a>&emsp;&emsp;
        <a href=#>로그인</a>&nbsp;
        <a href=#>로그아웃</a>&emsp;
        <a href=index.php>홈으로</a>
</nav>
<section> <br><br>
    <div align=center><font size=4><b>고등학교 성적처리 프로그램</b></font></div>
     <br>
     &emsp;1.학생 성적 정보 테이블을 생성한다. <br>
     &emsp;2.학생 성적 테이블에 샘플데이터를 SQL문을 이용하여 추가한다.<br>
     &emsp;3.주어진 화면 디자인을 이용하여 화면을 디자인 한다.<br>
     &emsp;4.업무 여건에 따라 프로그램을 작성한다.<br>
     <br></section>
<footer>Copyright (C) Microsoft Corporation. All rights reserved.</footer>
</div>
</body>
    
</html>

 


폴더 추가하기 

top.php head 부분에 

 <?
    $host= $_SERVER['HTTP_HOST'];
    $path="http://".$host;
    $rootPath=$_SERVER['DOCUMENT_ROOT'];
    ?>
추가하기 
 
<nav>
        &emsp;&emsp;&emsp;
        <a href=<?=$path?>/A_school/form.php>학생등록</a>&nbsp;
        <a href=<?=$path?>/A_school/list.php>학생목록/수정</a>&emsp;&emsp;
        <a href=<?=$path?>/B_big/insert.php>빅데이터추가</a>&nbsp;
        <a href=<?=$path?>/B_big/list1.php>페이지나누기1</a>&nbsp;
        <a href=<?=$path?>/B_big/list2.php>페이지나누기2</a>&emsp;&emsp;
        <a href=<?=$path?>/C_admin/login.php>로그인</a>&nbsp;
        <a href=<?=$path?>/C_admin/logout.php>로그아웃</a>&emsp;
        <a href=index.php>홈으로</a>
</nav>
 
top.php


<html>
<head>
    <? 
    $host= $_SERVER['HTTP_HOST'];
    $path="http://".$host;
    $rootPath=$_SERVER['DOCUMENT_ROOT'];
    ?>
<style>
.
.
.
.
.
.
<nav>
        &emsp;&emsp;&emsp;
        <a href=<?=$path?>/A_school/form.php>학생등록</a>&nbsp;
        <a href=<?=$path?>/A_school/list.php>학생목록/수정</a>&emsp;&emsp;
        <a href=<?=$path?>/B_big/insert.php>빅데이터추가</a>&nbsp;
        <a href=<?=$path?>/B_big/list1.php>페이지나누기1</a>&nbsp;
        <a href=<?=$path?>/B_big/list2.php>페이지나누기2</a>&emsp;&emsp;
        <a href=<?=$path?>/C_admin/login.php>로그인</a>&nbsp;
        <a href=<?=$path?>/C_admin/logout.php>로그아웃</a>&emsp;
        <a href=index.php>홈으로</a>
</nav>
사이트의 절대경로 추가하기 
 

폴더 만들고 파일 옮긴 다음 

index.php 파일에 

<?$rootPath=$_SERVER['DOCUMENT_ROOT'];?>

<? include  $rootPath."/D_include/top.php"?>
<? include  $rootPath."/D_include/bottom.php"?>
추가하기 
index.php


<?$rootPath=$_SERVER['DOCUMENT_ROOT'];?>

<? include  $rootPath."/D_include/top.php"?>

<section> 
    <br><br>
    <div align=center><font size=4><b>고등학교 성적처리 프로그램</b></font></div>
     <br>
     &emsp;1.학생 성적 정보 테이블을 생성한다. <br>
     &emsp;2.학생 성적 테이블에 샘플데이터를 SQL문을 이용하여 추가한다.<br>
     &emsp;3.주어진 화면 디자인을 이용하여 화면을 디자인 한다.<br>
     &emsp;4.업무 여건에 따라 프로그램을 작성한다.<br>
     <br>
</section>

<? include  $rootPath."/D_include/bottom.php"?>
 

각폴더에 파일 만들기 , index.php 내용 복사해서 수정하기 

insert.php



<?$rootPath=$_SERVER['DOCUMENT_ROOT'];?>

<? include  $rootPath."/D_include/top.php"?>

<section> 
    <br><br>
    <div align=center><font size=4><b>빅데이터 등록</b></font></div>
     <br><br><br><br>
     <h1 align=center> 빅데이터 등록이 완료되었습니다. </h1>
     <br>
</section>

<? include  $rootPath."/D_include/bottom.php"?>
list1.php




<?$rootPath=$_SERVER['DOCUMENT_ROOT'];?>

<? include  $rootPath."/D_include/top.php"?>

<section> 
    <br><br>
    <div align=center><font size=4><b>목록보기 (페이지나누기1)</b></font></div>
     <br>
    
     <br>
</section>

<? include  $rootPath."/D_include/bottom.php"?>
list2.php



<?$rootPath=$_SERVER['DOCUMENT_ROOT'];?>

<? include  $rootPath."/D_include/top.php"?>

<section> 
    <br><br>
    <div align=center><font size=4><b>목록보기 (페이지나누기2)</b></font></div>
     <br>
     
     <br>
</section>

<? include  $rootPath."/D_include/bottom.php"?>
login.php



<?$rootPath=$_SERVER['DOCUMENT_ROOT'];?>

<? include  $rootPath."/D_include/top.php"?>

<section> 
    <br><br>
    <div align=center><font size=4><b>로그인</b></font></div>
     <br>
    
     <br>
</section>

<? include  $rootPath."/D_include/bottom.php"?>
logout.php



<?$rootPath=$_SERVER['DOCUMENT_ROOT'];?>

<? include  $rootPath."/D_include/top.php"?>

<section> 
    <br><br>
    <div align=center><font size=4><b>로그아웃</b></font></div>
     <br><br><br><br>
     <h1 align=center> 로그아웃 완료!!!! </h1>
     <br>
</section>

<? include  $rootPath."/D_include/bottom.php"?>

 

create table board0628(
idx int not null AUTO_INCREMENT PRIMARY KEY,
    name varchar(10) not null,
    age varchar(50) not null,
    title varchar(100),
    etc varchar(200)
);

korea에 테이블 만들기 

insert.php



<?$rootPath=$_SERVER['DOCUMENT_ROOT'];?>

<? include  $rootPath."/D_include/top.php"?>

<section> 
    <br><br>
    <div align=center><font size=4><b>빅데이터 등록</b></font></div>
    <div align=center><br><br>
     <? 
     for($i=0; $i<=11; $i++){
        $name_rand=mt_rand(0,9);
        $name_array=array('하나','두리','세리','네리','다리','여리','일리','팔리','구리','테니');
        $name= $name_array[$name_rand];

        $age= mt_rand(11,25);

        $title_rand=mt_rand(0,4);
        $title_array=array('asp 중급','자바 초급','웹프로그램 고급','전산 실무','데이터베이스 튜닝');
        $title= $title_array[$title_rand];
        
        $etc_rand=mt_rand(0,1);
        $etc_array=array('전공학생','비전공학생');
        $etc=$etc_array[$etc_rand];

        $conn= new mysqli ("localhost","root","autoset","korea");
        $SQL= "insert into board0628 (name,age,title,etc) 
               values('$name','$age','$title','$etc')";
        $conn->query($SQL);
        echo $i."&nbsp;";
        $conn->close();

     }
     ?>
     
     <br>
    </div>
</section>

<? include  $rootPath."/D_include/bottom.php"?>

 


list1.php



<?$rootPath=$_SERVER['DOCUMENT_ROOT'];?>

<? include  $rootPath."/D_include/top.php"?>

<?php
$conn= new mysqli ("localhost","root","autoset","korea");
$SQL= "select idx,name,age,title,etc from board0628
       order by idx desc limit 0,9";
    
$result= $conn->query($SQL);

?>

<section> 
    <br><br>
    <div align=center><font size=4><b>목록보기 (페이지나누기1)</b></font></div>
    <div align=center><br>
    <table border=1 width=500>
    <tr>
        <th>번호</th><th>이름</th><th>나이</th><th>제목</th><th>특이사항</th>
    </tr>
     <? while($rs=$result->fetch_assoc()){?>
      <tr align=center>
        <td><?=$rs['idx']?></td>
        <td><?=$rs['name']?> </td>
        <td><?=$rs['age']?></td> 
        <td><?=$rs['title']?></td> 
        <td><?=$rs['etc']?> </td>
     </tr>
     <?}?>
     
     <br>
    </table></div>
</section>

<? include  $rootPath."/D_include/bottom.php"?>

-이름, 제목 가지고 검색하기 만들기 

</table> 밑에 <form>안에 select, option, input type 

list1.php


$conn= new mysqli ("localhost","root","autoset","korea"); //conn 밑에 ch1,ch2 변수 받기

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

$SQL= "select idx,name,age,title,etc from board0628
       order by idx desc limit 0,10";

       if($ch1==""){
        $SQL="select idx,name,age,title,etc from board0628 //if문 작성하기 
       order by idx desc limit 0,10";
       }else if($ch1=="name"){
        $SQL="select idx,name,age,title,etc from board0628 where name like '%$ch2%'
        order by idx desc limit 0,10";
       }else if($ch1=="title"){
        $SQL="select idx,name,age,title,etc from board0628 where title like '%$ch2%'
        order by idx desc limit 0,10";
       }
.
.
.
.
.
.
</table>
    <form>
        <select name=ch1> 
        <option value="name">이름</option>
        <option value="title">제목</option>
        </select>
        <input type= text name=ch2>
        <input type="submit" value="검색하기">
     </form>
     
     .
     .
     .

제목: 자바 검색결과

 


-count를 이용해서 테이블 위에 전체레코드 출력해보기 

$SQL= "select idx,name,age,title,etc from board0628
       order by idx desc limit 0,10";

//전체 레코드 수
$SQL_tc="select count(*) tc from board0628

       if($ch1==""){
        $SQL="select idx,name,age,title,etc from board0628
       order by idx desc limit 0,10";
       $SQL_tc="select count(*) tc from board0628
       order by idx desc limit 0,10";
       }else if($ch1=="name"){
         $SQL_tc="select count(*) tc from board0628 where name like '%$ch2%'
        order by idx desc limit 0,10";
        $SQL_tc="select count(*) tc from board0628 where name like '%$ch2%' //조건에 맞는 전체레코드수
        order by idx desc limit 0,10";
       }else if($ch1=="title"){
        $SQL="select idx,name,age,title,etc from board0628 where title like '%$ch2%'
        order by idx desc limit 0,10";
        $SQL_tc="select count(*) tc from board0628 where title like '%$ch2%' //조건에 맞는 전체레코드수
        order by idx desc limit 0,10";
       }
       
       $result_tc= $conn->query($SQL_tc);
$rs_tc =$result_tc->fetch_assoc();
$tc= $rs_tc['tc'];

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

.
.
.
.
.
전체레코드: <?=$tc?>
    <table border=1 width=500>

전체레코드
이름: 일리로 검색한 레코드

-순번 찍기

  <tr>
        <th>순번</th><th>번호</th><th>이름</th><th>나이</th><th>제목</th><th>특이사항</th>
    </tr>
     <? 
     $i=1;
     while($rs=$result->fetch_assoc()){?>
        
      <tr align=center>
        <td align=center><?=$i?></td>
        <td><?=$rs['idx']?></td>
        <td><?=$rs['name']?> </td>
        <td><?=$rs['age']?></td> 
        <td><?=$rs['title']?></td> 
        <td><?=$rs['etc']?> </td>
     </tr>
     <? $i++; }?>