--- .idea/dataSources/482ad897-bf06-4872-a94f-ca218d669792.xml
+++ .idea/dataSources/482ad897-bf06-4872-a94f-ca218d669792.xml
... | ... | @@ -1088,44 +1088,54 @@ |
1088 | 1088 |
<Position>7</Position> |
1089 | 1089 |
<DataType>varchar(300)|0s</DataType> |
1090 | 1090 |
</column> |
1091 |
- <key id="343" parent="333" name="PRIMARY"> |
|
1091 |
+ <column id="343" parent="333" name="listNum"> |
|
1092 |
+ <Position>8</Position> |
|
1093 |
+ <DataType>int(11)|0s</DataType> |
|
1094 |
+ <NotNull>1</NotNull> |
|
1095 |
+ <DefaultExpression>0</DefaultExpression> |
|
1096 |
+ </column> |
|
1097 |
+ <column id="344" parent="333" name="depth"> |
|
1098 |
+ <Position>9</Position> |
|
1099 |
+ <DataType>varchar(255)|0s</DataType> |
|
1100 |
+ </column> |
|
1101 |
+ <key id="345" parent="333" name="PRIMARY"> |
|
1092 | 1102 |
<NameSurrogate>1</NameSurrogate> |
1093 | 1103 |
<ColNames>num</ColNames> |
1094 | 1104 |
<Primary>1</Primary> |
1095 | 1105 |
</key> |
1096 |
- <column id="344" parent="334" name="id"> |
|
1106 |
+ <column id="346" parent="334" name="id"> |
|
1097 | 1107 |
<Position>1</Position> |
1098 | 1108 |
<DataType>varchar(255)|0s</DataType> |
1099 | 1109 |
<NotNull>1</NotNull> |
1100 | 1110 |
</column> |
1101 |
- <column id="345" parent="334" name="pw"> |
|
1111 |
+ <column id="347" parent="334" name="pw"> |
|
1102 | 1112 |
<Position>2</Position> |
1103 | 1113 |
<DataType>varchar(255)|0s</DataType> |
1104 | 1114 |
<NotNull>1</NotNull> |
1105 | 1115 |
</column> |
1106 |
- <column id="346" parent="335" name="num"> |
|
1116 |
+ <column id="348" parent="335" name="num"> |
|
1107 | 1117 |
<Position>1</Position> |
1108 | 1118 |
<DataType>int(11)|0s</DataType> |
1109 | 1119 |
<NotNull>1</NotNull> |
1110 | 1120 |
<SequenceIdentity>null</SequenceIdentity> |
1111 | 1121 |
</column> |
1112 |
- <column id="347" parent="335" name="con_num"> |
|
1122 |
+ <column id="349" parent="335" name="con_num"> |
|
1113 | 1123 |
<Position>2</Position> |
1114 | 1124 |
<DataType>int(11)|0s</DataType> |
1115 | 1125 |
</column> |
1116 |
- <column id="348" parent="335" name="reply_writer"> |
|
1126 |
+ <column id="350" parent="335" name="reply_writer"> |
|
1117 | 1127 |
<Position>3</Position> |
1118 | 1128 |
<DataType>varchar(50)|0s</DataType> |
1119 | 1129 |
</column> |
1120 |
- <column id="349" parent="335" name="reply_content"> |
|
1130 |
+ <column id="351" parent="335" name="reply_content"> |
|
1121 | 1131 |
<Position>4</Position> |
1122 | 1132 |
<DataType>varchar(100)|0s</DataType> |
1123 | 1133 |
</column> |
1124 |
- <column id="350" parent="335" name="reply_pw"> |
|
1134 |
+ <column id="352" parent="335" name="reply_pw"> |
|
1125 | 1135 |
<Position>5</Position> |
1126 | 1136 |
<DataType>int(11)|0s</DataType> |
1127 | 1137 |
</column> |
1128 |
- <key id="351" parent="335" name="PRIMARY"> |
|
1138 |
+ <key id="353" parent="335" name="PRIMARY"> |
|
1129 | 1139 |
<NameSurrogate>1</NameSurrogate> |
1130 | 1140 |
<ColNames>num</ColNames> |
1131 | 1141 |
<Primary>1</Primary> |
--- .idea/inspectionProfiles/Project_Default.xml
+++ .idea/inspectionProfiles/Project_Default.xml
... | ... | @@ -9,5 +9,6 @@ |
9 | 9 |
<option name="processLiterals" value="true" /> |
10 | 10 |
<option name="processComments" value="true" /> |
11 | 11 |
</inspection_tool> |
12 |
+ <inspection_tool class="SqlRedundantOrderingDirectionInspection" enabled="false" level="WARNING" enabled_by_default="false" /> |
|
12 | 13 |
</profile> |
13 | 14 |
</component>(No newline at end of file) |
+++ answerWriteFront.php
... | ... | @@ -0,0 +1,54 @@ |
1 | +<?php | |
2 | +/** | |
3 | + * @var $connStatus | |
4 | + */ | |
5 | +include("config/db.config.php"); | |
6 | +session_start(); | |
7 | +if (!isset($_SESSION['is_login'])){ | |
8 | + header('Location:index.php'); | |
9 | +} | |
10 | +?> | |
11 | +<!doctype html> | |
12 | +<html lang="ko"> | |
13 | +<head> | |
14 | + <meta charset="UTF-8"> | |
15 | + <meta name="viewport" | |
16 | + content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> | |
17 | + <meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
18 | + <title>Document</title> | |
19 | + <style> | |
20 | + #page {width: 80%;margin: 0 auto;background-color: antiquewhite; height: 500px;} | |
21 | + #conn {width: 80%;margin: 0 auto;} | |
22 | + #title {text-align: center;} | |
23 | + #hr {border-style: solid;} | |
24 | + #contents {width: 80%; margin: 0 auto;} | |
25 | + #form {width: 56.5%;} | |
26 | + #text1 {width: 250px; float: right;} | |
27 | + #text2 {width: 250px; float: right;} | |
28 | + #text3 {width: 500px; height: 250px; float: right;} | |
29 | + .btn {font-weight: bolder; background-color: darkslategrey; border: black solid; color: white; height: 30px; width: 50px; float: right;} | |
30 | + .btn:hover {background-color: black;} | |
31 | + #textareaHeight {height: 250px;} | |
32 | + </style> | |
33 | +</head> | |
34 | +<body> | |
35 | +<div id="conn"> | |
36 | + <?php | |
37 | + echo $connStatus; //DB 연결 상태 표시 | |
38 | + ?> | |
39 | +</div> | |
40 | +<div id="page"> | |
41 | + <div id="title"><h1>답글 쓰기</h1></div> | |
42 | + <hr id="hr"> | |
43 | + <div id="contents"> | |
44 | + <form id="form" method="post" action="config/answerWriteBack.php?whereValue=<?php echo $_GET['whereValue']?>&option=<?php echo $_GET['option']?>&searchText=<?php echo $_GET['searchText']?>"> | |
45 | + <p>작성자 : <input id="text1" type="text" name="writer"></p> | |
46 | + 제목 : <input id="text2" type="text" name="title" placeholder="최대 50자"> | |
47 | + <p id="textareaHeight">글 : <textarea id="text3" name="contents" placeholder="최대 500자"></textarea></p> | |
48 | + <input type="submit" class="btn" value="작성"> | |
49 | + </form> | |
50 | + <button class="btn" onclick="location.href='view.php?whereValue=<?php echo $_GET['whereValue'];?>&option=<?php echo $_GET['option']?>&searchText=<?php echo $_GET['searchText']?>'">취소</button> | |
51 | + </div> | |
52 | +</div> | |
53 | +</body> | |
54 | +</html>(No newline at end of file) |
+++ config/answerWriteBack.php
... | ... | @@ -0,0 +1,70 @@ |
1 | +<?php | |
2 | +/** | |
3 | + * @var $mysqli | |
4 | + */ | |
5 | +ini_set("display_errors", 1); | |
6 | +include("db.config.php"); | |
7 | + | |
8 | +/* 변수 초기화 : start */ | |
9 | +$writer= $_POST['writer']; //작성자 | |
10 | +$query = ""; //쿼리문 | |
11 | +/* 변수 초기화 : end */ | |
12 | +$whereValue = $_GET['whereValue']; | |
13 | +$option = $_GET['option']; | |
14 | +$text = $_GET['searchText']; | |
15 | + | |
16 | +/* 게시물 입력 정보 POST : start */ | |
17 | +if($writer != null){ | |
18 | + $writer= $_POST['writer']; | |
19 | +}else{ | |
20 | + $writer = "Anonymous"; | |
21 | +} | |
22 | +$title = $_POST['title']; | |
23 | +$contents = $_POST['contents']; | |
24 | +$date = date('Y:m:d'); | |
25 | +/* 게시물 입력 정보 POST : end */ | |
26 | + | |
27 | +/* 답글의 depth값 확인 */ | |
28 | +$queryDepthCheck = "select depth from data where num = '$whereValue'"; | |
29 | +$resultDepthCheck = $mysqli->query($queryDepthCheck); | |
30 | +$rowDepthCheck = $resultDepthCheck->fetch_array(); | |
31 | +/***************************************************************************************/ | |
32 | + | |
33 | +/* 최상위 부모글의 num */ | |
34 | +while($rowDepthCheck[0] == 0){ | |
35 | + $rowDepthCheck[0] = $rowDepthCheck[0] - 1; | |
36 | +} | |
37 | +$queryCheckTopListNum = "select listNum from data where depth = '$rowDepthCheck[0]'"; | |
38 | +$resultCheckTopListNum = $mysqli->query($queryCheckTopListNum); | |
39 | +$rowCheckTopListNum = $resultCheckTopListNum->fetch_array(); | |
40 | +/***************************************************************************************/ | |
41 | + | |
42 | +if($title != null){ /* 제목 공백일시 confirm */ | |
43 | + if($rowDepthCheck[0] < 1){ /* 이중 답글인지 확인 */ | |
44 | + $query = "insert into data (num, writer, title, contents, date, depth, listNum) | |
45 | + values(null, '$writer', '$title', '$contents', '$date', '1', '$whereValue')"; | |
46 | + | |
47 | + $query2 = "update data set listNum = '$whereValue' where num='$whereValue'"; | |
48 | + if($query && $query2){ | |
49 | + $result = $mysqli->query($query); | |
50 | + $result2 = $mysqli->query($query2); | |
51 | + echo "<script>alert('글이 등록되었습니다.');</script>"; | |
52 | + echo "<meta http-equiv='refresh' content='0.1; url=../main.php'>"; | |
53 | + }else{ | |
54 | + echo "FAIL"; | |
55 | + } | |
56 | + }else{ /* 답글에 답글이 달릴때 */ | |
57 | + $depthPlusOne = $rowDepthCheck[0]+1; | |
58 | + $query = "insert into data (num, writer, title, contents, date, depth, listNum) /*-> 최상위 부모글의 num */ | |
59 | + values(null, '$writer', '$title', '$contents', '$date', '$depthPlusOne', '$rowCheckTopListNum[0]')"; | |
60 | + if($query){ | |
61 | + $result = $mysqli->query($query); | |
62 | + echo "<script>alert('글이 등록되었습니다.');</script>"; | |
63 | + echo "<meta http-equiv='refresh' content='0.1; url=../main.php'>"; | |
64 | + } | |
65 | + } | |
66 | +}else{ //if title == null | |
67 | + echo "<script>alert('제목을 입력하세요!')</script>"; | |
68 | + | |
69 | + echo "<meta http-equiv='refresh' content='0.1; url=../answerWriteFront.php?whereValue=$whereValue&option=$option&searchText=$text'>"; | |
70 | +}(No newline at end of file) |
--- config/delete.php
+++ config/delete.php
... | ... | @@ -1,18 +1,38 @@ |
1 | 1 |
<?php |
2 | 2 |
/** |
3 |
- * @var $mysqli |
|
4 |
- */ |
|
5 |
-ini_set("display_errors", 0); |
|
6 |
-include("db.config.php"); |
|
3 |
+* @var $mysqli |
|
4 |
+*/ |
|
5 |
+ ini_set("display_errors", 0); |
|
6 |
+ include("db.config.php"); |
|
7 | 7 |
|
8 |
-$num = $_GET['whereValue']; |
|
8 |
+ $num = $_GET['whereValue']; |
|
9 |
+ $zero = 0; |
|
9 | 10 |
|
10 |
-$query = "delete from data where num=$num"; |
|
11 |
-$result = $mysqli->query($query); |
|
11 |
+ /* 부모글의 listNum 가져오기 */ |
|
12 |
+ $queryCheck2 = "select listNum from data where num=$num"; |
|
13 |
+ $resultCheck2 = $mysqli->query($queryCheck2); |
|
14 |
+ $row = $resultCheck2->fetch_array(); |
|
15 |
+ /**************************************************************************/ |
|
12 | 16 |
|
13 |
-unlink("/home/hw/www/download/".$_GET['file']); //DB 행 삭제 시 서버측 파일까지 삭제 |
|
17 |
+ /* 삭제하려는 답글의 listNum을 가진 모든 행의 개수 구하기 */ |
|
18 |
+ $queryCheck = "select count(*) from data where listNum = $row[0]"; |
|
19 |
+ $resultCheck = $mysqli->query($queryCheck); |
|
20 |
+ $rowCheck = $resultCheck->fetch_array(); |
|
21 |
+ /**************************************************************************/ |
|
14 | 22 |
|
15 |
-echo "<script>alert('삭제를 완료했습니다.');</script>"; |
|
16 |
-echo "<meta http-equiv='refresh' content='0.1; url=../main.php'>"; |
|
23 |
+ if($rowCheck[0] > 2){ /* 답글이 하나만 달린 부모 글의 답글이 삭제되면 해당 부모글의 listNum 0 처리 */ |
|
24 |
+ null; |
|
25 |
+ }else{ |
|
26 |
+ $query2 = "update data set listNum = $zero where listNum = $row[0]"; |
|
27 |
+ $result2 = $mysqli->query($query2); |
|
28 |
+ } |
|
17 | 29 |
|
18 |
-mysqli_close($mysqli); |
|
30 |
+ $query = "delete from data where num=$num"; |
|
31 |
+ $result = $mysqli->query($query); |
|
32 |
+ |
|
33 |
+ unlink("/home/hw/www/download/".$_GET['file']); //DB 행 삭제 시 서버측 파일까지 삭제 |
|
34 |
+ |
|
35 |
+ echo "<script>alert('삭제를 완료했습니다.');</script>"; |
|
36 |
+ echo "<meta http-equiv='refresh' content='0.1; url=../main.php'>"; |
|
37 |
+ |
|
38 |
+ mysqli_close($mysqli); |
--- config/select.php
+++ config/select.php
... | ... | @@ -38,12 +38,12 @@ |
38 | 38 |
$query = "select * from data where writer like '". "%" . $text . "%" ."' order by num desc limit $page_start, $list"; |
39 | 39 |
$query2 = "select * from data where writer like '". "%" . $text . "%" ."' order by num desc"; |
40 | 40 |
}else{ |
41 |
- $query = "select * from data order by num desc limit $page_start, $list"; //MAX 7개 출력 |
|
41 |
+ $query = "select * from data order by listNum desc, depth asc limit $page_start, $list"; //MAX 7개 출력 |
|
42 | 42 |
$query2 = "select * from data"; |
43 | 43 |
} |
44 | 44 |
$result = $mysqli->query($query); //전체 행 조회 for PRINT |
45 | 45 |
|
46 |
-$resultCount = $mysqli->query($query2); //전체 행 조회 for COUNT cause LIMIT |
|
46 |
+$resultCount = $mysqli->query($query2); //전체 행 조회 for COUNT cause LIMIT |
|
47 | 47 |
$searchCount = $resultCount->num_rows; // 검색시 나온 행 갯수 COUNT |
48 | 48 |
|
49 | 49 |
$total_page = ceil($searchCount / $list); //총 페이징 숫자 수 |
... | ... | @@ -51,4 +51,4 @@ |
51 | 51 |
$block_end = $total_page; |
52 | 52 |
} |
53 | 53 |
$total_block = ceil($total_page / $block_cnt); //총 블록 수 |
54 |
-?> |
|
54 |
+ |
--- main.php
+++ main.php
... | ... | @@ -56,6 +56,7 @@ |
56 | 56 |
#a {text-decoration:none; color: black; font-weight: bold;} |
57 | 57 |
#a:hover {background-color: tomato;} |
58 | 58 |
#selectNum {color: red; display: inline; } |
59 |
+ #tableTitle {text-align: left;} |
|
59 | 60 |
</style> |
60 | 61 |
</head> |
61 | 62 |
<body> |
... | ... | @@ -95,8 +96,22 @@ |
95 | 96 |
?> |
96 | 97 |
<tbody> <!-- 메인 컨텐츠 출력 --> |
97 | 98 |
<tr> |
98 |
- <td><?php echo $row['num']; ?></td> |
|
99 |
- <td> |
|
99 |
+ <td><?php |
|
100 |
+ if($row['depth'] == 0){ /* 답글은 게시글 번호 출력 X */ |
|
101 |
+ echo $row['num']; |
|
102 |
+ }else{ |
|
103 |
+ null; |
|
104 |
+ } |
|
105 |
+ ?> |
|
106 |
+ </td> |
|
107 |
+ <td id="tableTitle"> |
|
108 |
+ <?php |
|
109 |
+ if($row['depth'] > 0){ |
|
110 |
+ echo "<img height=1 alt='' width=" . $row['depth']*15 . ">└>"; |
|
111 |
+ }else{ |
|
112 |
+ null; |
|
113 |
+ } |
|
114 |
+ ?> |
|
100 | 115 |
<a id="a" href="./view.php?whereValue=<?php echo $row['num'];?>&cnt=<?php echo $row['view']+1;?>&option=<?php echo$option?>&searchText=<?php echo $text?>"> <!-- view.php --> |
101 | 116 |
<?php echo $row['title']; ?> |
102 | 117 |
</a> |
--- view.php
+++ view.php
... | ... | @@ -81,6 +81,7 @@ |
81 | 81 |
<br>첨부파일 : <a href="config/download.php?file=<?php echo $row['file']?>&whereValue=<?php echo $row['num']?>&option=<?php echo $_GET['option']?>&searchText=<?php echo $text?>"><?php echo $row['file'];?></a> |
82 | 82 |
</div> |
83 | 83 |
<div id="btnControl"> |
84 |
+ <button class="btnS" id="btnAnswer" onclick="location.href='answerWriteFront.php?whereValue=<?php echo $row['num'];?>&option=<?php echo $_GET['option']?>&searchText=<?php echo $text?>'">답글</button> |
|
84 | 85 |
<button class="btnS" id="btnUpdate" onclick="location.href='updateWrite.php?whereValue=<?php echo $row['num'];?>&option=<?php echo $_GET['option']?>&searchText=<?php echo $text?>'">수정</button> |
85 | 86 |
<button class="btnS" id="btnDelete" onclick="deleteCheck()">삭제</button> |
86 | 87 |
<button class="btnS" id="btnList" onclick="location.href='main.php?&option=<?php echo $_GET['option']?>&searchText=<?php echo $text?>'">목록</button> |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?