-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser-list.php
200 lines (188 loc) · 8.91 KB
/
user-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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<?php
require_once("pdo-connect.php");
$sql = "SELECT id, account, name, created_at, valid FROM users WHERE valid!=9";
$stmt=$db_host->prepare($sql);
try{
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$userCount=$stmt->rowCount();
}catch(PDOException $e){
echo $e->getMessage();
}
for ($i=0; $i<count($rows); $i++){
$sqlDogs = "SELECT user_id, COUNT(id) AS dog_count FROM pets WHERE category='dog' AND user_id=? GROUP BY user_id";
$sqlCats = "SELECT user_id, COUNT(id) AS cat_count FROM pets WHERE category='cat' AND user_id=? GROUP BY user_id";
$stmtDogs=$db_host->prepare($sqlDogs);
$stmtDogs->execute([$rows[$i]["id"]]);
$userDogs = $stmtDogs->fetchAll(PDO::FETCH_ASSOC);
$stmtCats=$db_host->prepare($sqlCats);
$stmtCats->execute([$rows[$i]["id"]]);
$userCats = $stmtCats->fetchAll(PDO::FETCH_ASSOC);
// var_dump($userDogs);
// echo "<br>";
$dogCountArr=array_column($userDogs, "dog_count");
$catCountArr=array_column($userCats, "cat_count");
foreach($dogCountArr as $dogCount){
$rows[$i]["dogs"]=$dogCount;
}
foreach($catCountArr as $catCount){
$rows[$i]["cats"]=$catCount;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
<meta name="Description" content="MaoBook小組專題報告"/>
<meta name="Content-Language" content="zh-TW">
<meta name="author" content="Team MaoBook"/>
<!-- 網站圖示 -->
<link rel="apple-touch-icon" type="image/png" href="images/logo-nbg.png"/>
<link rel="shortcut icon" type="image/png" href="images/logo-nbg.png"/>
<link rel="mask-icon" type="image/png" href="images/logo-nbg.png"/>
<title>會員列表</title>
<?php require_once("style.php"); ?>
<style>
#th-id{
width: 7%;
}
#th-account{
width: 15%;
}
#th-created-at{
width: 20%;
}
#th-valid{
width: 8%;
}
#th-dog-count, #th-cat-count{
width: 10%;
}
.pet-icon{
width: 20px;
}
</style>
</head>
<body class="sb-nav-fixed">
<?php require_once("main-nav.php"); ?>
<!-- 主要內容 -->
<div id="layoutSidenav_content">
<div class="container px-0">
<main class="main px-5">
<div class="container-fluid px-2">
<h1 class="mt-4">會員列表</h1>
<ol class="breadcrumb mb-4">
<li class="breadcrumb-item"><a href="home.php">首頁</a></li>
<li class="breadcrumb-item active">會員列表</li>
</ol>
<div class="py-2 d-flex justify-content-end" >
<button class="col-auto mb-3 col-2 btn btn-outline-warning text-white" role="button" onclick="window.location.href='user-add.php'">新 增 會 員</button>
</div>
<!-- <div class="btn-group" role="group" aria-label="Basic outlined example">-->
<!-- <button type="button" class="btn btn-outline-warning text-white">新增會員</button>-->
<!-- <button type="button" class="btn btn-outline-warning text-white">刪除會員</button>-->
<!-- </div>-->
<!-- <div>--><?//=var_dump($rows)?><!--</div>-->
<!-- 副標題 end -->
<div class="card mb-4">
<div class="card-header">
<i class="fas fa-table me-1"></i>
資料表格
</div>
<!-- 表格區塊 -->
<div class="card-body">
<table id="datatablesSimple">
<!-- 標題欄 -->
<thead>
<tr>
<!-- 表格註腳 thead -->
<th id="th-id">ID</th>
<th id="th-account">帳號</th>
<th>名稱</th>
<th id="th-created-at">建立時間</th>
<th id="th-valid">狀態</th>
<th id="th-dog-count">狗狗數</th>
<th id="th-cat-count">貓貓數</th>
<th>其他操作</th>
</tr>
</thead>
<!-- 總結資訊 tfoot -->
<tfoot>
<tr>
<th>ID</th>
<th>帳號</th>
<th>名稱</th>
<th>建立時間</th>
<th>狀態</th>
<th>狗狗數</th>
<th>貓貓數</th>
<th>其他操作</th>
</tr>
</tfoot>
<!-- 資料欄 tbody -->
<tbody>
<?php if ($userCount > 0):
foreach($rows as $user):?>
<tr>
<td><?= $user["id"] ?></td>
<td><?= $user["account"] ?></td>
<td><?= $user["name"] ?></td>
<td><?= $user["created_at"] ?></td>
<td>
<?php if($user["valid"]==1): ?>
一般
<?php else: ?>
封鎖中
<?php endif; ?>
</td>
<td>
<?php if(isset($user["dogs"])): ?>
<img class="pet-icon me-1" src="images/dog.png" alt="">
<?= $user["dogs"] ?>
<?php else:?>
<img class="pet-icon me-1" src="images/dog.png" alt="">
0
<?php endif;?>
</td>
<td>
<?php if(isset($user["cats"])): ?>
<img class="pet-icon me-1" src="images/cat.png" alt="">
<?= $user["cats"] ?>
<?php else:?>
<img class="pet-icon me-1" src="images/cat.png" alt="">
0
<?php endif;?>
</td>
<td>
<a class="btn btn-mao-primary " href="user.php?id=<?=$user["id"]?>"
title="檢視此會員資料">
<i class="fas fa-user"></i></a>
<a class="btn btn-mao-primary" href="user-edit.php?id=<?= $user["id"] ?>"
title="編輯此會員資料">
<i class="fas fa-edit"></i></a>
<a class="btn btn-mao-primary " href="user-order.php?id=<?=$user["id"]?>"
title="會員訂單">
<i class="fas fa-credit-card "></i></a>
</td>
</tr>
<?php endforeach; ?>
<?php else: ?>
<tr>
<td colspan="4">沒有資料</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div><!-- 表格區塊 end-->
</div>
</main><!-- 主要內容end -->
</div>
<!-- --><?php //require_once("footer.php"); ?>
<!--</div>-->
</div>
<?php require_once("JS.php"); ?>
</body>
</html>