This repository has been archived by the owner on May 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
my-list.php
98 lines (93 loc) · 3.35 KB
/
my-list.php
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
<?php
session_start();
require 'config.php';
if(isset($_SESSION['access_token'])) {
$access_token = $_SESSION['access_token'];
} else {
header("Location: sign-in.php?url=".$_SERVER['REQUEST_URI']);
}
$page_title = "내 지도(목록으로 보기)";
include_once("header.php");
// MySQL 데이터베이스 연결
$mysqli = new mysqli('localhost', DB_ID, DB_PW, 'gabolga');
// 연결 오류 발생 시 스크립트 종료
if ($mysqli->connect_errno) {
die('Connect Error: '.$mysqli->connect_error);
}
$query = "SELECT my_map.tweet_id, name, road_address, address, phone, add_time FROM my_map LEFT JOIN tweet ON my_map.tweet_id = tweet.tweet_id WHERE user_id = {$access_token['user_id']} ORDER BY tweet.road_address DESC";
$count = 0;
?>
<div class="container">
<h3>
내 지도(목록으로 보기)
<small class="text-muted">가볼가 한 장소를 목록으로 봅니다.</small>
</h3>
<table id="list" class="table table-hover">
<thead>
<tr>
<th>#</th>
<th>이름</th>
<th class="mobile">주소</th>
<th class="mobile">전화번호</th>
<th class="mobile">추가일</th>
<th>-</th>
</tr>
</thead>
<tbody>
<?php
if ($result = $mysqli->query($query)) {
while($data = $result->fetch_assoc()) {
$count++;
if($data['name'] != "") {
echo "<tr>
<th onclick=\"link('{$data['tweet_id']}')\" scope=\"row\">{$count}</th>
<td onclick=\"link('{$data['tweet_id']}')\">{$data['name']}</td>";
if($data['road_address'] != "") {
echo "<td class=\"mobile\" onclick=\"link('{$data['tweet_id']}')\">{$data['road_address']}({$data['address']})</td>";
} else {
echo "<td class=\"mobile\" onclick=\"link('{$data['tweet_id']}')\">{$data['address']}</td>";
}
echo "<td class=\"mobile\" onclick=\"link('{$data['tweet_id']}')\">".($data['phone']!=""?$data['phone']:'-')."</td>
<td class=\"mobile\" onclick=\"link('{$data['tweet_id']}')\">{$data['add_time']}</td>
<td><button id=\"{$data['tweet_id']}\" class=\"btn btn-danger list_btn\" onclick=\"add_remove('{$data['tweet_id']}')\">가볼가 취소</button></td>
</tr>";
} else {
echo "<tr>
<th onclick=\"link('{$data['tweet_id']}')\" scope=\"row\">{$count}</th>
<td onclick=\"link('{$data['tweet_id']}')\" colspan=\"4\">장소 정보를 등록해주세요 ;^;</td>
<td><button id=\"{$data['tweet_id']}\" class=\"btn btn-danger list_btn\" onclick=\"add_remove('{$data['tweet_id']}')\">가볼가 취소</button></td>
</tr>";
}
}
$result->free();
}
$mysqli->close();
if($count == 0) {
echo "<tr>
<td colspan=\"6\">앗! 가볼가 한 트윗이 없어요!</td>
</tr>";
}
?>
<script>
function add_remove(tweet_id) {
$.get("add-remove.php?tweet_id="+tweet_id, function(data) {
if($("#"+tweet_id).text() == "가볼가 하기") {
$("#"+tweet_id).text("가볼가 취소");
$("#"+tweet_id).addClass("btn-danger");
$("#"+tweet_id).removeClass("btn-primary");
} else {
$("#"+tweet_id).text("가볼가 하기");
$("#"+tweet_id).addClass("btn-primary");
$("#"+tweet_id).removeClass("btn-danger");
}
});
}
function link(tweet_id) {
window.open("tweet.php?tweet_id="+tweet_id,"","");
}
</script>
</tbody>
</table>
</div>
</body>
</html>