728x90
개인적인 메모를 위해 작성된 글이므로 가벼운 참고용으로 봐주세요.
작성
<?php
$title = $_GET['title'];
$body = $_GET['body'];
$sql = "
INSERT INTO article
SET regDate = NOW(),
title = '{$title}',
`body` = '{$body}'
";
echo "[게시물작성] 제목: {$title} / 내용: {$body}";
$dbHost = '127.0.0.1';
$dbLoginId = 'sbsst';
$dbLoginPw = 'sbs123414';
$dbName = 'site3';
$conn = mysqli_connect($dbHost, $dbLoginId, $dbLoginPw, $dbName);
mysqli_query($conn, $sql);
리스트
<meta charset="UTF-8">
<?php
$dbHost = '127.0.0.1';
$dbLoginId = 'sbsst';
$dbLoginPw = 'sbs123414';
$dbName = 'site3';
$conn = mysqli_connect($dbHost, $dbLoginId, $dbLoginPw, $dbName);
$sql = "
SELECT *
FROM article
ORDER BY id DESC
";
$rs = mysqli_query($conn, $sql);
$rows = [];
while ( $row = mysqli_fetch_assoc($rs) ) {
$rows[] = $row;
}
?>
<h1>게시물 리스트</h1>
<?php foreach ( $rows as $row ) { ?>
<table border="3">
<thead>
<tr>
<th>
번호
</th>
<th>
날짜
</th>
<th>
제목
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<?=$row['id']?>
</td>
<td>
<?=$row['regDate']?>
</td>
<td>
<?=$row['title']?>
</td>
</tr>
</tbody>
</table>
<?php } ?>
리스트검색
<meta charset="UTF-8">
<?php
$searchKeyword = $_GET['searchKeyword'];
$dbHost = '127.0.0.1';
$dbLoginId = 'sbsst';
$dbLoginPw = 'sbs123414';
$dbName = 'site3';
$conn = mysqli_connect($dbHost, $dbLoginId, $dbLoginPw, $dbName);
$sql = "
SELECT *
FROM article
WHERE title
LIKE '{$searchKeyword}'
ORDER BY id DESC;
";
$rs = mysqli_query($conn, $sql);
$rows = [];
while ( $row = mysqli_fetch_assoc($rs) ) {
$rows[] = $row;
}
?>
<h1>게시물 리스트</h1>
<?php foreach ( $rows as $row ) { ?>
<div><?=$row['id']?> / <?=$row['regDate']?> / <?=$row['title']?></div>
<?php } ?>
삭제
<?php
$id = $_GET['id'];
$sql = "
DELETE
FROM article
WHERE id = '{$id}'
";
echo "{$id}번 게시물 삭제됐습니다.";
$dbHost = '127.0.0.1';
$dbLoginId = 'sbsst';
$dbLoginPw = 'sbs123414';
$dbName = 'site3';
$conn = mysqli_connect($dbHost, $dbLoginId, $dbLoginPw, $dbName);
mysqli_query($conn, $sql);
수정
<?php
$title = $_GET['title'];
$body = $_GET['body'];
$id = $_GET['id'];
$sql = "
update article
set title = '{$title}',
body = '{$body}'
WHERE id = '{$id}'
";
echo "{$id}번 게시물 제목: {$title} / 내용: {$body} 으로 수정합니다.";
$dbHost = '127.0.0.1';
$dbLoginId = 'sbsst';
$dbLoginPw = 'sbs123414';
$dbName = 'site3';
$conn = mysqli_connect($dbHost, $dbLoginId, $dbLoginPw, $dbName);
mysqli_query($conn, $sql);
상세
<meta charset="UTF-8">
<?php
$dbHost = '127.0.0.1';
$dbLoginId = 'sbsst';
$dbLoginPw = 'sbs123414';
$dbName = 'site3';
$conn = mysqli_connect($dbHost, $dbLoginId, $dbLoginPw, $dbName);
$id = $_GET['id'];
$sql = "
SELECT *
FROM article
WHERE id = '{$id}'
";
$rs = mysqli_query($conn, $sql);
$rows = [];
while ( $row = mysqli_fetch_assoc($rs) ) {
$rows[] = $row;
}
?>
<h1>게시물 상세페이지</h1>
<table border="1">
<tbody>
<?php foreach ( $rows as $row ) { ?>
<tr>
<th>번호</th>
<td><?=$row['id']?></td>
</tr>
<tr>
<th>날짜</th>
<td><?=$row['regDate']?></td>
</tr>
<tr>
<th>제목</th>
<td><?=$row['title']?></td>
</tr>
<tr>
<th>내용</th>
<td><?=$row['body']?></td>
</tr>
<?php } ?>
</tbody>
</table>
728x90
반응형
'IT관련 > JAVA_자유 노트' 카테고리의 다른 글
[수업창작] 20-05-31 (0) | 2020.05.31 |
---|---|
[수업창작] 20-05-30 (0) | 2020.05.30 |
txt파일 저장/불러오기/존재유무 코드 (0) | 2020.05.25 |
[수업창작] 20-05-23(MVC구조 회원가입) (0) | 2020.05.23 |
[수업창작] 20-05-21(저장한파일을 글로벌클래스로 카운팅) (0) | 2020.05.22 |
댓글