--- 20220209/Address.php
+++ 20220209/Address.php
... | ... | @@ -23,12 +23,24 @@ |
23 | 23 |
|
24 | 24 |
public function getList(){ |
25 | 25 |
try { |
26 |
- $stmt = $this->db->prepare("select * from address"); |
|
26 |
+ $stmt = $this->db->prepare("select * from address LIMIT 0, 5"); |
|
27 | 27 |
$stmt->execute(); |
28 | 28 |
$result = $stmt->fetchAll(); |
29 | 29 |
return $result; |
30 | 30 |
}catch (Exception $e){ |
31 | 31 |
echo $e; |
32 |
+ } |
|
33 |
+ } |
|
34 |
+ |
|
35 |
+ public function getListPage($limitStart, $onePage){ |
|
36 |
+ try { |
|
37 |
+ $sql = "select * from address limit " . $limitStart . ", " . $onePage; |
|
38 |
+ $stmt = $this->db->prepare($sql); |
|
39 |
+ $stmt->execute(); |
|
40 |
+ $result = $stmt->fetchAll(); |
|
41 |
+ return $result; |
|
42 |
+ }catch (Exception $e){ |
|
43 |
+ return $e; |
|
32 | 44 |
} |
33 | 45 |
} |
34 | 46 |
|
... | ... | @@ -65,6 +77,19 @@ |
65 | 77 |
} |
66 | 78 |
} |
67 | 79 |
|
80 |
+ public function getCountList(){ |
|
81 |
+ try { |
|
82 |
+ $sql = "select count(*) as count from address"; |
|
83 |
+ $stmt = $this->db->prepare($sql); |
|
84 |
+ $stmt->execute(); |
|
85 |
+ $result = $stmt->fetch(); |
|
86 |
+ return $result; |
|
87 |
+ }catch(Exception $e){ |
|
88 |
+ return $e; |
|
89 |
+ } |
|
90 |
+ |
|
91 |
+ } |
|
92 |
+ |
|
68 | 93 |
|
69 | 94 |
|
70 | 95 |
} |
--- 20220209/address_view.php
+++ 20220209/address_view.php
... | ... | @@ -1,7 +1,15 @@ |
1 | 1 |
<?php |
2 |
+/** |
|
3 |
+ * @var $paging |
|
4 |
+ * @var $limitStart |
|
5 |
+ * @var $onePage |
|
6 |
+ */ |
|
7 |
+ require_once("page.php"); |
|
2 | 8 |
require_once("Address.php"); |
3 | 9 |
$address = new Address(); |
4 |
- $list = $address->getList(); |
|
10 |
+ $list = $address->getListPage($limitStart, $onePage); |
|
11 |
+ |
|
12 |
+ $addressCount = $address->getCountList(); |
|
5 | 13 |
?> |
6 | 14 |
<!doctype html> |
7 | 15 |
<html lang="ko"> |
... | ... | @@ -14,8 +22,11 @@ |
14 | 22 |
<style> |
15 | 23 |
* {margin: 0 auto; padding: 0; text-align: center;} |
16 | 24 |
td, th {padding: 10px;} |
17 |
- a {text-decoration: none; color: red;} |
|
18 |
- a:hover {background-color: tomato; color: black;} |
|
25 |
+ a {text-decoration: none; width: 100%; height: 100%; color: black;} |
|
26 |
+ a:hover {background-color: black; color: white;} |
|
27 |
+ li {display: inline-block; border: 1px solid black; padding: 5px;} |
|
28 |
+ li:hover{background-color: black; color: white;} |
|
29 |
+ ul {margin-top: 30px;} |
|
19 | 30 |
</style> |
20 | 31 |
</head> |
21 | 32 |
<body> |
... | ... | @@ -69,6 +80,7 @@ |
69 | 80 |
</tr> |
70 | 81 |
<?php }?> |
71 | 82 |
</table> |
83 |
+ <?php echo $paging; ?> |
|
72 | 84 |
</body> |
73 | 85 |
</html> |
74 | 86 |
|
+++ 20220209/page.php
... | ... | @@ -0,0 +1,86 @@ |
1 | +<?php | |
2 | + | |
3 | + require_once("Address.php"); | |
4 | + $address = new Address(); | |
5 | + | |
6 | + //페이지 get 변수가 있다면 받아오고 없으면 1페이지을 보여줌 | |
7 | + if(isset($_GET['page'])){ | |
8 | + $page = $_GET['page']; | |
9 | + }else{ | |
10 | + $page = 1; | |
11 | + } | |
12 | + | |
13 | + | |
14 | + | |
15 | + | |
16 | + //전체 게시글 카운팅 | |
17 | + $row = $address->getCountList(); | |
18 | + $allPost = $row['count']; | |
19 | + | |
20 | + //한 페이지에 보여줄 게시글 수 | |
21 | + $onePage = 5; | |
22 | + | |
23 | + //전체 페이지 수 | |
24 | + $allPage = ceil($allPost/$onePage); | |
25 | + | |
26 | + //page variable | |
27 | + $paging = "<ul>"; | |
28 | + | |
29 | + //처음페이지로 이동 | |
30 | + if($page > 1){ | |
31 | + $paging .= "<li><a href='address_view.php?page=" . (1) . "'>처음</a></li>"; | |
32 | + } | |
33 | + | |
34 | + //이전페이지로 이동 | |
35 | + $pre = $page - 1; | |
36 | + //이전 페이지 예외처리 | |
37 | + if($page > 1){ | |
38 | + $paging .= "<li><a href='address_view.php?page=" . $pre . "'>이전</a></li>"; | |
39 | + } | |
40 | + | |
41 | + for($i = 1; $i<=$allPage; $i++){ | |
42 | + if($page == $i){ | |
43 | + $back = "tomato"; | |
44 | + }else{ | |
45 | + $back = "none"; | |
46 | + } | |
47 | + $paging .= "<li style='background-color: " . $back . "' ><a href='address_view.php?page=" . $i . "'>" . $i . "</a></li>"; | |
48 | + } | |
49 | + | |
50 | + //다음페이지로 이동 | |
51 | + $next = $page + 1; | |
52 | + //페이지 예외처리 | |
53 | + if($page < $allPage){ | |
54 | + $paging .= "<li><a href='address_view.php?page=" . $next . "'>다음</a></li>"; | |
55 | + } | |
56 | + | |
57 | + //처음페이지로 이동 | |
58 | + if($page < $allPage){ | |
59 | + $paging .= "<li><a href='address_view.php?page=" . $allPage . "'>마지막</a></li>"; | |
60 | + } | |
61 | + | |
62 | + | |
63 | + $paging .= "</ul>"; | |
64 | + | |
65 | + //limit 세팅 | |
66 | + $limitStart = ($onePage * $page) - $onePage; | |
67 | + | |
68 | + | |
69 | + | |
70 | + | |
71 | + | |
72 | + | |
73 | + | |
74 | + | |
75 | + | |
76 | + | |
77 | + | |
78 | + | |
79 | + | |
80 | + | |
81 | + | |
82 | + | |
83 | + | |
84 | + | |
85 | + | |
86 | + |
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?