--- 20220209/Address.php
+++ 20220209/Address.php
... | ... | @@ -32,9 +32,9 @@ |
32 | 32 |
} |
33 | 33 |
} |
34 | 34 |
|
35 |
- public function getListPage($limitStart, $onePage){ |
|
35 |
+ public function getListPage($limitStart, $onePage, $searchSql){ |
|
36 | 36 |
try { |
37 |
- $sql = "select * from address limit " . $limitStart . ", " . $onePage; |
|
37 |
+ $sql = "select * from address" . $searchSql . "limit " . $limitStart . ", " . $onePage; |
|
38 | 38 |
$stmt = $this->db->prepare($sql); |
39 | 39 |
$stmt->execute(); |
40 | 40 |
$result = $stmt->fetchAll(); |
... | ... | @@ -77,9 +77,9 @@ |
77 | 77 |
} |
78 | 78 |
} |
79 | 79 |
|
80 |
- public function getCountList(){ |
|
80 |
+ public function getCountList($searchSql){ |
|
81 | 81 |
try { |
82 |
- $sql = "select count(*) as count from address"; |
|
82 |
+ $sql = "select count(*) as count from address " . $searchSql; |
|
83 | 83 |
$stmt = $this->db->prepare($sql); |
84 | 84 |
$stmt->execute(); |
85 | 85 |
$result = $stmt->fetch(); |
--- 20220209/address_view.php
+++ 20220209/address_view.php
... | ... | @@ -3,13 +3,13 @@ |
3 | 3 |
* @var $paging |
4 | 4 |
* @var $limitStart |
5 | 5 |
* @var $onePage |
6 |
+ * @var $searchSql |
|
6 | 7 |
*/ |
7 | 8 |
require_once("page.php"); |
8 | 9 |
require_once("Address.php"); |
9 | 10 |
$address = new Address(); |
10 |
- $list = $address->getListPage($limitStart, $onePage); |
|
11 | 11 |
|
12 |
- $addressCount = $address->getCountList(); |
|
12 |
+ $list = $address->getListPage($limitStart, $onePage, $searchSql); |
|
13 | 13 |
?> |
14 | 14 |
<!doctype html> |
15 | 15 |
<html lang="ko"> |
... | ... | @@ -81,6 +81,20 @@ |
81 | 81 |
<?php }?> |
82 | 82 |
</table> |
83 | 83 |
<?php echo $paging; ?> |
84 |
+ <div class="searchBar"><br> |
|
85 |
+ <form action="address_view.php" method="get"> |
|
86 |
+ <label for="searchKey"> |
|
87 |
+ <select name="searchKey"> |
|
88 |
+ <option value="">전체</option> |
|
89 |
+ <option value="name">이름</option> |
|
90 |
+ </select> |
|
91 |
+ </label> |
|
92 |
+ <label for="searchWord"> |
|
93 |
+ <input type="text" name="searchWord"> |
|
94 |
+ </label> |
|
95 |
+ <button type="submit">검색</button> |
|
96 |
+ </form> |
|
97 |
+ </div> |
|
84 | 98 |
</body> |
85 | 99 |
</html> |
86 | 100 |
|
--- 20220209/page.php
+++ 20220209/page.php
... | ... | @@ -10,8 +10,13 @@ |
10 | 10 |
$page = 1; |
11 | 11 |
} |
12 | 12 |
|
13 |
+ $searchKey = isset($_GET['searchKey']) ? $_GET['searchKey'] : ""; |
|
14 |
+ $searchWord = isset($_GET['searchWord']) ? $_GET['searchWord'] : ""; |
|
15 |
+ $searchSql = ($searchKey != "") ? " where " . $searchKey . " LIKE '%" . $searchWord . "%' " : " "; |
|
16 |
+ |
|
17 |
+ |
|
13 | 18 |
//전체 게시글 카운팅 |
14 |
- $row = $address->getCountList(); |
|
19 |
+ $row = $address->getCountList($searchSql); |
|
15 | 20 |
$allPost = $row['count']; |
16 | 21 |
|
17 | 22 |
//한 페이지에 보여줄 게시글 수 |
... | ... | @@ -24,31 +29,38 @@ |
24 | 29 |
//한 블록에 보여줄 페이지 |
25 | 30 |
$oneBlock = 5; |
26 | 31 |
|
27 |
- //블록의 첫 페이지 |
|
28 |
- $firstPage = $page - floor($oneBlock / 2); |
|
29 |
- if($page == 1 || $page == 2){ |
|
30 |
- $firstPage = 1; |
|
32 |
+ |
|
33 |
+ if($allPage > $oneBlock){ |
|
34 |
+ $firstPage = $page - floor($oneBlock / 2); |
|
35 |
+ if($page == 1 || $page == 2){ |
|
36 |
+ $firstPage = 1; |
|
37 |
+ } |
|
38 |
+ |
|
39 |
+ //블록의 마지막 페이지 |
|
40 |
+ $lastPage = $page + floor($oneBlock / 2); |
|
41 |
+ if($page == $allPage || $page == ($allPage-1)){ |
|
42 |
+ $lastPage = $allPage; |
|
43 |
+ } |
|
31 | 44 |
} |
32 | 45 |
|
33 |
- //블록의 마지막 페이지 |
|
34 |
- $lastPage = $page + floor($oneBlock / 2); |
|
35 |
- if($page == $allPage || $page == ($allPage-1)){ |
|
36 |
- $lastPage = $allPage; |
|
37 |
- } |
|
46 |
+ //블록의 첫 페이지 |
|
47 |
+ |
|
48 |
+ |
|
49 |
+ |
|
38 | 50 |
|
39 | 51 |
//page variable |
40 | 52 |
$paging = "<ul>"; |
41 | 53 |
|
42 | 54 |
//처음페이지로 이동 |
43 | 55 |
if($page > 1){ |
44 |
- $paging .= "<li><a href='address_view.php?page=" . (1) . "'>처음</a></li>"; |
|
56 |
+ $paging .= "<li><a href='address_view.php?page=" . (1) . "&searchKey=" . $searchKey . "&searchWord=" . $searchWord . "'>처음</a></li>"; |
|
45 | 57 |
} |
46 | 58 |
|
47 | 59 |
//이전페이지로 이동 |
48 | 60 |
$pre = $page - 1; |
49 | 61 |
//이전 페이지 예외처리 |
50 | 62 |
if($page > 1){ |
51 |
- $paging .= "<li><a href='address_view.php?page=" . $pre . "'>이전</a></li>"; |
|
63 |
+ $paging .= "<li><a href='address_view.php?page=" . $pre . "&searchKey=" . $searchKey . "&searchWord=" . $searchWord . "'>이전</a></li>"; |
|
52 | 64 |
} |
53 | 65 |
|
54 | 66 |
for($i = $firstPage; $i<=$lastPage; $i++){ |
... | ... | @@ -57,22 +69,20 @@ |
57 | 69 |
}else{ |
58 | 70 |
$back = "none"; |
59 | 71 |
} |
60 |
- $paging .= "<li style='background-color: " . $back . "' ><a href='address_view.php?page=" . $i . "'>" . $i . "</a></li>"; |
|
72 |
+ $paging .= "<li style='background-color: " . $back . "' ><a href='address_view.php?page=" . $i . "&searchKey=" . $searchKey . "&searchWord=" . $searchWord . "'>" . $i . "</a></li>"; |
|
61 | 73 |
} |
62 | 74 |
|
63 | 75 |
//다음페이지로 이동 |
64 | 76 |
$next = $page + 1; |
65 | 77 |
//페이지 예외처리 |
66 | 78 |
if($page < $allPage){ |
67 |
- $paging .= "<li><a href='address_view.php?page=" . $next . "'>다음</a></li>"; |
|
79 |
+ $paging .= "<li><a href='address_view.php?page=" . $next . "&searchKey=" . $searchKey . "&searchWord=" . $searchWord . "'>다음</a></li>"; |
|
68 | 80 |
} |
69 | 81 |
|
70 | 82 |
//처음페이지로 이동 |
71 | 83 |
if($page < $allPage){ |
72 | 84 |
$paging .= "<li><a href='address_view.php?page=" . $allPage . "'>마지막</a></li>"; |
73 | 85 |
} |
74 |
- |
|
75 |
- |
|
76 | 86 |
$paging .= "</ul>"; |
77 | 87 |
|
78 | 88 |
//limit 세팅 |
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?