[PHP]데이터리스트 DATA LIST(list01.php)

list01.php파일의 소스코드 입니다.
입력된 데이터를 보여주는 부분입니다.
데이터베이스 접속,인증 부분은 기존 부분과 동일 합니다.
자세히 살펴봐야 될 부분은 다음과 같습니다.

This is the source code of the list01.php file.
This part shows the entered data.
The database connection and authentication parts are the same as the existing parts.
Here are some things to look at in detail

1.SQL QUERY
testuser 테이블에서 id필드를 기준으로 내림차준 정렬하고 10개의 게시물을 0번째 다음부터 검색합니다.
Sort the testuser table in descending order based on the id field and search for the 10 posts starting from 0.

   $sql = "select * from testuser order by id desc limit 10 offset 0";
   $result = $mysqli->query($sql);

2.$row = $result->fetch_assoc()
실행된 결과를 배열로 가지고 와서 화면에 출력합니다.
Runs the results and displays them on the screen.

   while($row = $result->fetch_assoc()){
    $r_id     = $row['id']; 
    $r_name   = $row['name'];
    $r_title  = $row['title'];

    echo "<tr><td>" . $r_id . "</td><td>" . $r_name . "</td><td>" . $r_title . "</td></tr>";
    
   }
<!DOCTYPE html>
<html>
    <head>
    ​  <title>List파일</title>
        <!--이 부분은 html코멘트 영역 This part is the html comment area,마임타입설정 Mime type settings//-->
      <meta charset="utf-8">
      <!-- 모바일폰 스크린 옵션 Mobile phone screen options//-->
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <!--부트스트랩5 CDN방식 링크 Bootstrap 5 CDN method link//-->
      <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet">
      <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>

   </head>
   <body>
<!--테이블 시작 table start //-->
<div class="container mt-3">
  <table class="table table-dark table-hover">
   <tr>
      <td>ID</td><td>이름</td><td>제목</td>
   </tr>
<?php
   //데이터베이스 인증
   //DATABASE AUTENTICATION
   $servername = "localhost";
   $username = " ";
   $password = " ";
   $dbname = " ";

   //데이터 베이스 접속 
   //DATABASE CONNECTION
   $mysqli = new mysqli($servername,$username,$password,$dbname);
   
   //데이터베이스 접속체크
   //DATABASE CONNECTION CHECK
   if($mysqli->connect_error){
      die("connect failed". $mysqli->connect_error);
   
   }
   // SQL QUERY
   $sql = "select * from testuser order by id desc limit 10 offset 0";
   $result = $mysqli->query($sql);
   while($row = $result->fetch_assoc()){
    $r_id     = $row['id']; 
    $r_name   = $row['name'];
    $r_title  = $row['title'];

    echo "<tr><td>" . $r_id . "</td><td>" . $r_name . "</td><td>" . $r_title . "</td></tr>";
    
   }

   $mysqli->close();
?>
      <tr>
         <td colspan=3><a href="form6.php">write</a></td>
      </tr>
   </table>
</div>
<!--테이블 끝table end//-->
   </body>
</html>

아래의 링크를 통해서 테스트 할 수 있습니다
You can test it through the link below
https://freelifemakers.org/lec/list01.php

Leave a Reply

Your email address will not be published. Required fields are marked *