
회원명단을 json파일로 저장한후에 저장된 회원명단을 웹에서 볼수 있게 만들어 보았습니다.
회원수가 적은 경우에는 데이타베이스를 사용하는 것 보다 간편하게 사용할 수 있는 것 같습니다.
압축을 풀면 test 폴더안에 data.json, images folder, look.php 파일이 나옵니다.
test폴더를 통째로 업로드합니다.
example.com/test/look.php 경로가 됩니다.
json 파일에 회원항목을 추가하거나 변경하고, 이미지를 원하는데로 바꾸면 될 것 같습니다.
look.php에서 테이블을 변경하면 보기좋게 나올 것 같습니다.
chatgpt의 도움을 받았습니다.
data.json
[code][
{
"이름": "John Doe",
"전화번호": "010-1234-5678",
"주소": "New York",
"이메일": "john@example.com",
"소개": "Hello",
"사진": "images/1.png"
},
{
"이름": "Jane Smith",
"전화번호": "010-2345-6789",
"주소": "Los Angeles",
"이메일": "jane@example.com",
"소개": "Nice to meet you",
"사진": "images/2.png"
},
{
"이름": "David Brown",
"전화번호": "010-3456-7890",
"주소": "Chicago",
"이메일": "david@example.com",
"소개": "I love coding",
"사진": "images/3.png"
},
{
"이름": "Emily White",
"전화번호": "010-4567-8901",
"주소": "San Francisco",
"이메일": "emily@example.com",
"소개": "Passionate about design",
"사진": "images/4.png"
},
{
"이름": "Michael Green",
"전화번호": "010-5678-9012",
"주소": "Miami",
"이메일": "michael@example.com",
"소개": "Outdoor enthusiast",
"사진": "images/5.png"
},
{
"이름": "Sophia Taylor",
"전화번호": "010-6789-0123",
"주소": "Houston",
"이메일": "sophia@example.com",
"소개": "Music lover",
"사진": "images/6.png"
},
{
"이름": "James Johnson",
"전화번호": "010-7890-1234",
"주소": "Boston",
"이메일": "james@example.com",
"소개": "Football fan",
"사진": "images/7.png"
},
{
"이름": "Olivia Martinez",
"전화번호": "010-8901-2345",
"주소": "Seattle",
"이메일": "olivia@example.com",
"소개": "Art and photography",
"사진": "images/8.png"
},
{
"이름": "Benjamin Harris",
"전화번호": "010-9012-3456",
"주소": "Austin",
"이메일": "benjamin@example.com",
"소개": "Tech geek",
"사진": "images/9.png"
},
{
"이름": "Charlotte Lewis",
"전화번호": "010-0123-4567",
"주소": "Dallas",
"이메일": "charlotte@example.com",
"소개": "Traveler",
"사진": "images/10.png"
},
{
"이름": "Henry Clark",
"전화번호": "010-1234-5678",
"주소": "Phoenix",
"이메일": "henry@example.com",
"소개": "Caffeine addict",
"사진": "images/11.png"
},
{
"이름": "Ava Walker",
"전화번호": "010-2345-6789",
"주소": "San Diego",
"이메일": "ava@example.com",
"소개": "Fitness enthusiast",
"사진": "images/12.png"
}
][/code]
look.php
[code]
<?php
// data.json 파일에서 JSON 데이터 읽기
$jsonData = file_get_contents('data.json');
$dataArray = json_decode($jsonData, true);
// 데이터가 없으면 빈 배열로 초기화
if ($dataArray === null) {
$dataArray = [];
}
// 검색 기능
$searchName = isset($_GET['search_name']) ? $_GET['search_name'] : '';
// 검색된 결과 필터링
if ($searchName) {
$filteredData = array_filter($dataArray, function($member) use ($searchName) {
return stripos($member['이름'], $searchName) !== false; // 이름을 포함하는 경우
});
} else {
// 검색어가 없으면 모든 데이터 출력
$filteredData = $dataArray;
}
?>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>회원 목록</title>
<style>
table {
width: 100%;
border-collapse: collapse;
}
table, th, td {
border: 1px solid black;
}
th, td {
padding: 8px;
text-align: left;
}
img {
width: 50px; /* 이미지 크기 조정 */
height: 50px;
}
</style>
</head>
<body>
<h1>회원 목록</h1>
<!-- 검색 폼 -->
<form method="GET" action="look.php">
<label for="search_name">회원 이름 검색:</label>
<input type="text" id="search_name" name="search_name" value="<?php echo htmlspecialchars($searchName); ?>" placeholder="이름을 입력하세요">
<button type="submit">검색</button>
</form>
<h2>검색 결과</h2>
<table>
<thead>
<tr>
<th>이름</th>
<th>전화번호</th>
<th>주소</th>
<th>이메일</th>
<th>소개</th>
<th>사진</th> <!-- 사진 항목 추가 -->
</tr>
</thead>
<tbody>
<?php
// 필터링된 데이터 배열을 순회하며 테이블 행을 생성
if (count($filteredData) > 0) {
foreach ($filteredData as $member) {
echo "<tr>";
echo "<td>" . htmlspecialchars($member['이름']) . "</td>";
echo "<td>" . htmlspecialchars($member['전화번호']) . "</td>";
echo "<td>" . htmlspecialchars($member['주소']) . "</td>";
echo "<td>" . htmlspecialchars($member['이메일']) . "</td>";
echo "<td>" . htmlspecialchars($member['소개']) . "</td>";
// 이미지 출력
echo "<td><img src='" . htmlspecialchars($member['사진']) . "' alt='사진'></td>";
echo "</tr>";
}
} else {
echo "<tr><td colspan='6'>검색된 회원이 없습니다.</td></tr>";
}
?>
</tbody>
</table>
</body>
</html>
[/code]
댓글 6개
게시글 목록
| 번호 | 제목 |
|---|---|
| 63027 | |
| 63014 | |
| 63008 | |
| 62999 |
최신글
상단 탑배너(최신)
5
|
| 62953 | |
| 62943 | |
| 62941 | |
| 62936 |
최신글
상단 탑배너(최신)
4
|
| 62908 | |
| 62907 | |
| 62892 | |
| 62879 |
게시판
롤오버스킨
10
|

댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기