-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommunication_list.php
More file actions
136 lines (128 loc) · 3.48 KB
/
communication_list.php
File metadata and controls
136 lines (128 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Youth Is A Travel</title>
<link rel="stylesheet" type="text/css" href="./css/common.css">
<link rel="stylesheet" type="text/css" href="./css/communication.css">
</head>
<body>
<header>
<?php include "header.php";?>
</header>
<section id="mainlist">
<div id="communication_box">
<h3>
소통하자!
</h3>
<ul id="communication_list">
<li>
<span class="col1">번호</span>
<span class="col2">제목</span>
<span class="col3">글쓴이</span>
<span class="col4">첨부</span>
<span class="col5">등록일</span>
<span class="col6">조회</span>
</li>
<?php
if (isset($_GET["page"]))
$page = $_GET["page"];
else
$page = 1;
$con = mysqli_connect("localhost", "user1", "12345", "sample");
$sql = "select * from communication order by num desc";
$result = mysqli_query($con, $sql);
$total_record = mysqli_num_rows($result); // 전체 글 수
$scale = 10;
// 전체 페이지 수($total_page) 계산
if ($total_record % $scale == 0)
$total_page = floor($total_record/$scale);
else
$total_page = floor($total_record/$scale) + 1;
// 표시할 페이지($page)에 따라 $start 계산
$start = ($page - 1) * $scale;
$number = $total_record - $start;
for ($i=$start; $i<$start+$scale && $i < $total_record; $i++)
{
mysqli_data_seek($result, $i);
// 가져올 레코드로 위치(포인터) 이동
$row = mysqli_fetch_array($result);
// 하나의 레코드 가져오기
$num = $row["num"];
$id = $row["id"];
$name = $row["name"];
$subject = $row["subject"];
$regist_day = $row["regist_day"];
$hit = $row["hit"];
if ($row["file_name"])
$file_image = "<img src='./img/sub.png' height='20px' >";
else
$file_image = " ";
?>
<li>
<span class="col1"><?=$number?></span>
<span class="col2"><a href="communication_view.php?num=<?=$num?>&page=<?=$page?>"><?=$subject?></a></span>
<span class="col3"><?=$name?></span>
<span class="col4"><?=$file_image?></span>
<span class="col5"><?=$regist_day?></span>
<span class="col6"><?=$hit?></span>
</li>
<?php
$number--;
}
mysqli_close($con);
?>
</ul>
<ul id="page_num">
<?php
if ($total_page>=2 && $page >= 2)
{
$new_page = $page-1;
echo "<li><a href='communication_list.php?page=$new_page'>◀ 이전</a> </li>";
}
else
echo "<li> </li>";
// 게시판 목록 하단에 페이지 링크 번호 출력
for ($i=1; $i<=$total_page; $i++)
{
if ($page == $i) // 현재 페이지 번호 링크 안함
{
echo "<li><b> $i </b></li>";
}
else
{
echo "<li><a href='communication_list.php?page=$i'> $i </a><li>";
}
}
if ($total_page>=2 && $page != $total_page)
{
$new_page = $page+1;
echo "<li> <a href='communication_list.php?page=$new_page'>다음 ▶</a> </li>";
}
else
echo "<li> </li>";
?>
</ul> <!-- page -->
<ul class="buttons">
<li><button onclick="location.href='communication_list.php'">목록</button></li>
<li>
<?php
if($userid) {
?>
<button onclick="location.href='communication_form.php'">글쓰기</button>
<?php
} else {
?>
<a href="javascript:alert('로그인 후 이용해 주세요!')"><button>글쓰기</button></a>
<?php
}
?>
</li>
</ul>
</div> <!-- communication_box -->
</section>
<footer>
<?php include "footer.php";?>
</footer>
</body>
</html>