본문 바로가기

프로그래밍/게시판 만들기

메인화면 index.php(수정 중)

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>게시판</title>
    <style>
          table{
                  border-top: 1px solid #444444;
                  border-collapse: collapse;
          }
          tr{
                  border-bottom: 1px solid #444444;
                  padding: 10px;
          }
          td{
                  border-bottom: 1px solid #efefef;
                  padding: 10px;
          }
          table .even{
                  background: #efefef;
          }
          .text{
                  text-align:center;
                  padding-top:20px;
                  color:#000000
          }
          a:link {color : #57A0EE; text-decoration:none;}
          a:hover { text-decoration : underline;}
    </style>
  </head>

  <body>
    <?php
      $con = mysqli_connect('localhost', 'root', '----', '------') or die ("connect fail");
      $query ="select * from board order by number desc";
      $result=mysqli_query($con,$query);
      $total = mysqli_num_rows($result);

      session_start();

      if(isset($_SESSION['userid'])){
        echo $_SESSION['userid'];?>님 안녕하세요
        <br>
        <button onclick="location.href='logout.php'">로그아웃</button>
        <?php
      }
      else {
        ?>
        <button onclick="location.href='login.php'">로그인</button>
        <?php
      }
    ?>
    <h2 align=center>게시판</h2>
    <table align = center>
      <thead align = "center">
        <tr>
          <td width = "50" align="center">번호</td>
          <td width = "500" align = "center">제목</td>
          <td width = "100" align = "center">작성자</td>
          <td width = "200" align = "center">날짜</td>
          <td width = "50" align = "center">조회수</td>
        </tr>
      </thead>
      <tbody>
        <?php
          while($rows = mysqli_fetch_array($result)){ //DB에 저장된 데이터 수 (열 기준)
          if($total%2==0){
        ?><tr class = "even">
        <?php   }
          else{
        ?><tr>
        <?php } ?>
          <td width = "50" align = "center"><?php echo $total?></td>
          <td width = "500" align = "center">
          <a href = "view.php?number=<?php echo $rows['number']?>">
        <?php echo $rows['title']?></td>
          <td width = "100" align = "center"><?php echo $rows['id']?></td>
          <td width = "200" align = "center"><?php echo $rows['date']?></td>
          <td width = "50" align = "center"><?php echo $rows['hit']?></td>
          </tr>
        <?php
          $total--;
          }
        ?>
      </tbody>
  </table>
  <div class = text>
  <button onclick="location.href='write.php'" style="width:100px">글쓰기</button>
  </div>
  </body>
</html>