회원목록 출력형태
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
h1 {text-align: center;}
table {margin: 0 auto;}
</style>
<title>examSQL-10.php</title>
</head>
<body>
<h1>회원목록</h1>
<table>
<thead>
<tr>
<th>순번</th>
<th>아이디</th>
<th>성명</th>
<th>비밀번호</th>
<th>이메일</th>
<th>동작</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>hong</td>
<td>홍길동</td>
<td>hong</td>
<td>hong@nomail.plz</td>
<td>
<a href="./examSQL-14.php">삭제</a>
<a href="./examSQL-15.php">수정</a>
</td>
</tr>
<tr>
<td>2</td>
<td>yskim</td>
<td>김영삼</td>
<td>yskim</td>
<td>yskim@nomail.plz</td>
<td>
<a href="examSQL-14.php">삭제</a>
<a href="examSQL-15.php">수정</a>
</td>
</tr>
<tr>
<td>3</td>
<td>ysoh</td>
<td>오영수</td>
<td>ysoh</td>
<td>ysoh@nomail.plz</td>
<td>
<a href="examSQL-14.php">삭제</a>
<a href="examSQL-15.php">수정</a>
</td>
</tr>
</tbody>
</table>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
h1 {text-align: center;}
table {margin: 0 auto;}
</style>
<title>examSQL-11.php</title>
</head>
<body>
<h1>회원목록</h1>
<table>
<thead>
<tr>
<th>순번</th>
<th>아이디</th>
<th>성명</th>
<th>비밀번호</th>
<th>이메일</th>
<th>동작</th>
</tr>
</thead>
<tbody>
<?php
require './dbConn.php';
$link = mysqli_connect($dbHost, $dbUser, $dbPass); // MySQL 서버 연결
if (!$link) { // DB연결에 실패한 경우 ($!link, $link!=true, $link==false 모두 동일)
echo "DB 연결에 실패했습니다.<br/>";
exit(); // 프로그램 종료
}
$db = mysqli_select_db($link, $dbName); // Database 선택
if (!$db) { // DB선택에 실패한 경우 ($!$db, $db!=true, $db==false 모두 동일)
echo "{$dbName} 이름의 DB를 찾을 수 없습니다.<br/>";
exit(); // 프로그램 종료
}
$char = mysqli_set_charset($link, "utf8"); // DB 문자셋 설정
if (!$char) { // 문자셋 설정에 실패한 경우 ($!$char, $char!=true, $char==false 모두 동일)
echo "UTF-8 문자셋을 설정하지 못했습니다.<br/>";
exit(); // 프로그램 종료
}
$sql = "SELECT `userid`, `passwd`, `name`, `email` FROM `user`";
$result = mysqli_query($link, $sql); // SQL 실행
if (!$result) { // SQL에 오류가 있는 경우
echo "SQL에 오류가 있습니다.<br/>";
exit(); // 프로그램 종료
}
$no = 1;
while ($row = mysqli_fetch_array($result)) { // 루프를 돌며 검색된 결과에서 마지막이 될 때까지 레코드를 하나씩 가져옴
echo "<tr>";
echo "<td>$no</td>";
echo "<td>{$row["userid"]}</td>"; // 필드명을 키로하여 원하는 데이터에 접근
echo "<td>{$row["passwd"]}</td>";
echo "<td>{$row["name"]}</td>";
echo "<td>{$row["email"]}</td>";
echo "<td><a href='./examSQL-14.php'>삭제</a></td>";
echo "<td><a href='./examSQL-15.php'>수정</a></td>";
echo "</tr>";
$no ++;
}
mysqli_close($link); // MySQL 연결 종료
?>
</tbody>
</table>
</body>
</html>
examSQL-11.php 실행결과
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
h1 {text-align: center;}
table {margin: 0 auto;}
</style>
<title>examSQL-12.php</title>
</head>
<body>
<h1>회원목록</h1>
<table>
<thead>
<tr>
<th>순번</th>
<th>아이디</th>
<th>성명</th>
<th>비밀번호</th>
<th>이메일</th>
<th>동작</th>
</tr>
</thead>
<tbody>
<?php
require './dbConn.php';
$link = mysqli_connect($dbHost, $dbUser, $dbPass); // MySQL 서버 연결
if (!$link) { // DB연결에 실패한 경우 ($!link, $link!=true, $link==false 모두 동일)
echo "DB 연결에 실패했습니다.<br/>";
exit(); // 프로그램 종료
}
$db = mysqli_select_db($link, $dbName); // Database 선택
if (!$db) { // DB선택에 실패한 경우 ($!$db, $db!=true, $db==false 모두 동일)
echo "{$dbName} 이름의 DB를 찾을 수 없습니다.<br/>";
exit(); // 프로그램 종료
}
$char = mysqli_set_charset($link, "utf8"); // DB 문자셋 설정
if (!$char) { // 문자셋 설정에 실패한 경우 ($!$char, $char!=true, $char==false 모두 동일)
echo "UTF-8 문자셋을 설정하지 못했습니다.<br/>";
exit(); // 프로그램 종료
}
$sql = "SELECT `userid`, `passwd`, `name`, `email` FROM `user`";
$result = mysqli_query($link, $sql); // SQL 실행
if (!$result) { // SQL에 오류가 있는 경우
echo "SQL에 오류가 있습니다.<br/>";
exit(); // 프로그램 종료
}
$no = 1;
while ($row = mysqli_fetch_array($result)) { // 루프를 돌며 검색된 결과에서 마지막이 될 때까지 레코드를 하나씩 가져옴
?>
<tr>
<td><?= $no ?></td>
<td><?= $row["userid"] ?></td>
<td><?= $row["passwd"] ?></td>
<td><?= $row["name"] ?></td>
<td><?= $row["email"] ?></td>
<td><a href='./examSQL-14.php'>삭제</a></td>
<td><a href='./examSQL-15.php'>수정</a></td>
</tr>
<?php
$no ++;
}
mysqli_close($link); // MySQL 연결 종료
?>
</tbody>
</table>
</body>
</html>
examSQL-12.php 실행결과
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
h1 {text-align: center;}
table {margin: 0 auto;}
</style>
<title>examSQL-13.php</title>
</head>
<body>
<h1>회원목록</h1>
<table>
<thead>
<tr>
<th>순번</th>
<th>아이디</th>
<th>성명</th>
<th>비밀번호</th>
<th>이메일</th>
<th>동작</th>
</tr>
</thead>
<tbody>
<?php
require './dbConn.php';
$link = mysqli_connect($dbHost, $dbUser, $dbPass); // MySQL 서버 연결
if (!$link) { // DB연결에 실패한 경우 ($!link, $link!=true, $link==false 모두 동일)
echo "DB 연결에 실패했습니다.<br/>";
exit(); // 프로그램 종료
}
$db = mysqli_select_db($link, $dbName); // Database 선택
if (!$db) { // DB선택에 실패한 경우 ($!$db, $db!=true, $db==false 모두 동일)
echo "{$dbName} 이름의 DB를 찾을 수 없습니다.<br/>";
exit(); // 프로그램 종료
}
$char = mysqli_set_charset($link, "utf8"); // DB 문자셋 설정
if (!$char) { // 문자셋 설정에 실패한 경우 ($!$char, $char!=true, $char==false 모두 동일)
echo "UTF-8 문자셋을 설정하지 못했습니다.<br/>";
exit(); // 프로그램 종료
}
$sql = "SELECT `userid`, `passwd`, `name`, `email` FROM `user`";
$result = mysqli_query($link, $sql); // SQL 실행
if (!$result) { // SQL에 오류가 있는 경우
echo "SQL에 오류가 있습니다.<br/>";
exit(); // 프로그램 종료
}
$no = 1;
while ($row = mysqli_fetch_array($result)) { // 루프를 돌며 검색된 결과에서 마지막이 될 때까지 레코드를 하나씩 가져옴
?>
<tr>
<td><?= $no ?></td>
<td><?= $row["userid"] ?></td>
<td><?= $row["passwd"] ?></td>
<td><?= $row["name"] ?></td>
<td><?= $row["email"] ?></td>
<td><a href='./examSQL-14.php?userid=<?= $row["userid"] ?>'>삭제</a></td>
<td><a href='./examSQL-15.php?userid=<?= $row["userid"] ?>'>수정</a></td>
</tr>
<?php
$no ++;
}
mysqli_close($link); // MySQL 연결 종료
?>
</tbody>
</table>
</body>
</html>
examSQL-13.php 실행결과
관련