-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspringsummer_list.php
More file actions
138 lines (125 loc) · 3.4 KB
/
springsummer_list.php
File metadata and controls
138 lines (125 loc) · 3.4 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
137
138
<!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/springsummer.css">
</head>
<body>
<header>
<?php include "header.php";?>
</header>
<section id="mainlist">
<div class="container">
<h3 class="heading">
청명한 봄, 뜨거운 여름
</h3>
<div class="box-container">
<?php
if (isset($_GET["page"]))
$page = $_GET["page"];
else
$page = 1;
$con = mysqli_connect("localhost", "user1", "12345", "sample");
$sql = "select * from springsummer order by hit desc, num desc";
$result = mysqli_query($con, $sql);
$total_record = mysqli_num_rows($result); // 전체 글 수
$scale = 6;
// 전체 페이지 수($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"];
$file_copied = $row["file_copied"];
?>
<div class="box">
<?php
if (!empty($file_copied)) {
$real_name = $file_copied;
$file_path = "./data/".$real_name;
echo '<img src="' . $file_path . '" alt="이미지">';
} else {
echo '<img src="./img/Nophoto.png" alt="대체 이미지">';
}
?>
<a href="springsummer_view.php?num=<?=$num?>&page=<?=$page?>"><?=$subject?></a>
<span><?=$name?></span>
<span><?=$regist_day?></span>
<span class="hit"><?=$hit?></span>
</div>
<?php
$number--;
}
mysqli_close($con);
?>
</div>
</div>
<ul id="page_num">
<?php
if ($total_page>=2 && $page >= 2)
{
$new_page = $page-1;
echo "<li><a href='springsummer_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='springsummer_list.php?page=$i'> $i </a><li>";
}
}
if ($total_page>=2 && $page != $total_page)
{
$new_page = $page+1;
echo "<li> <a href='springsummer_list.php?page=$new_page'>다음 ▶</a> </li>";
}
else
echo "<li> </li>";
?>
</ul> <!-- page -->
<ul class="viewbuttons">
<li><button onclick="location.href='springsummer_list.php'">목록</button></li>
<li>
<?php
if($userid) {
?>
<button onclick="location.href='springsummer_form.php'">글쓰기</button>
<?php
} else {
?>
<a href="javascript:alert('로그인 후 이용해 주세요!')"><button>글쓰기</button></a>
<?php
}
?>
</li>
</ul>
<!-- </div> springsummer_box -->
</section>
<footer>
<?php include "footer.php";?>
</footer>
</body>
</html>