-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcategory.php
237 lines (181 loc) · 7.01 KB
/
category.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<?php
// 数据库连接信息
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "bowwow";
// 创建数据库连接
$conn = new mysqli($servername, $username, $password, $dbname);
// 检查连接是否成功
if ($conn->connect_error) {
die("Failed " . $conn->connect_error);
}
// 查询所有类别
$sql = "SELECT * FROM category";
$result = $conn->query($sql);
// 处理表单提交
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// 处理添加类别请求
if (isset($_POST["add_product"])) {
$name = $_POST["name"];
$price = $_POST["price"];
$description = $_POST["description"];
$sql = "INSERT INTO category (name, price, description) VALUES ('$name', '$price', '$description')";
if ($conn->query($sql) === TRUE) {
echo "scuessful";
} else {
echo "Failed: " . $conn->error;
}
}
// 处理编辑类别请求
if (isset($_POST["edit_category"])) {
$id = $_POST["id"];
$name = $_POST["name"];
$price = $_POST["price"];
$description = $_POST["description"];
$sql = "UPDATE products SET name='$name', price='$price', description='$description' WHERE id=$id";
if ($conn->query($sql) === TRUE) {
echo "scuessful";
} else {
echo "Failed: " . $conn->error;
}
}
// 处理删除类别请求
if (isset($_POST["delete_category"])) {
$id = $_POST["id"];
$sql = "DELETE FROM products WHERE id=$id";
if ($conn->query($sql) === TRUE) {
echo "scuessful";
} else {
echo "Failed: " . $conn->error;
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Category Management</title>
<!-- Remote style sheet -->
<link rel="stylesheet" href="https://unpkg.com/mdui@1.0.2/dist/css/mdui.min.css"/>
<script src="https://unpkg.com/mdui@1.0.2/dist/js/mdui.min.js"></script>
<!-- Local style sheet relative to workspace folder -->
<link rel="stylesheet" href="/style.css">
<script src="css/theme.css"></script>
<!-- Local style sheet relative to this file -->
<link rel="stylesheet" href="../theme.css">
<!-- Embedded style sheet -->
<style>
table.center{
margin:auto auto auto -20%;
width:115%;
border-collapse:collapse;
text-align: center;
}
table.center th, table.center td {
padding: 8px;
border-bottom: 1px solid #ddd;
}
table.center th{
background-color: #D8CCC4;
}
h2{
margin-left: -20%;
}
div.search_clearfix{
float:right;
margin-right:calc(5%);
}
</style>
</head>
<body>
<?php include("include/sidebar.php");?>
<div class="mdui-drawer-body-left" id="body" >
<!--主题-->
<h2>Category List</h2>
<!-- SEARCHING -->
<div class="margin" id="page_style">
<div class="operation clearfix">
<span class="submenu"><a href="addcategory.php" style ="margin-left:-20%;"class="mdui-btn mdui-btn-raised mdui-ripple mdui-color-amber-100" title="Add Category"><i class="fa fa-edit"></i> Add Category</a></span>
<div class="search_clearfix">
<label for="search">Category Searching:</label><input name="search" type="text" id="search" class="form-control col-xs-6"/><button class="mdui-btn mdui-btn-raised mdui-ripple mdui-color-amber-100" onclick="search" type="button" ><i class="fa fa-search"></i> Search</button>
<?php
// 如果搜索关键词不为空,执行搜索
if (!empty($_GET['search'])) {
// 连接数据库
$conn = mysqli_connect("localhost", "root", "", "bowwow");
// 获取搜索关键词
$search = mysqli_real_escape_string($conn, $_GET['search']);
// 构造查询语句
$query = "SELECT * FROM category WHERE name LIKE '%$search%' ORDER BY id DESC";
// 查询数据
$result = mysqli_query($conn, $query);
// 显示搜索结果
if (mysqli_num_rows($result) > 0) {
echo "<table>";
echo '<tr>
<th width="5%"><label><input type="checkbox" class="ace"><span class="lbl"></span></label></th>
<th width="10%">ID</th>
<th width="20%">Icon</th>
<th width="20%">Category Name</th>
<th width="15%">Status</th>
<th width="30%">Operation</th>
</tr>';
while ($row = mysqli_fetch_assoc($result)) {
echo "<table class='table table_list table_striped table-bordered center'>";
echo "<tr>";
echo '<td width="5%">'.'<label>'.'<input type="checkbox" class="ace"><span class="lbl">'.'</span>'.'</label>'.'</td>';
echo '<td width="10%">'.$row['id'].'</td>';
echo '<td width="20%"><img src="images/category_img/'.$row['id'].'.svg" alt="'.$row['image_path'].'"width="100px"height="100px"></td>';
echo '<td width="20%">'.$row['name'].'</td>';
echo '<td width="15%">' . ($row['status'] == 0 ? 'Activated' : ($row['status'] == 1 ? 'Forbidden' : '')) . '</td>';
echo '<td width="30%"><a href="cateedit.php?id='.$row['id'].'">Edit</a> ';
echo '<a href="Delete.php?cate=category&id='.$row['id'].'">Delete</a></td>';
echo "</tr>";
echo "</table>";
}
echo "</table>";
} else {
echo "No results found.";
}
// 关闭数据库连接
mysqli_close($conn);
}
?>
</div>
</div>
<!--列表展示-->
<h3>
<div class="list_Exhibition margin-sx">
<table class="table table_list table_striped table-bordered center" id="sample-table">
<tr>
<th width="5%"><label><input type="checkbox" class="ace"><span class="lbl"></span></label></th>
<th width="10%">ID</th>
<th width="20%">Icon</th>
<th width="20%">Category Name</th>
<th width="15%">Status</th>
<th width="30%">Operation</th>
</tr>
<?php
// 在这里添加您的PHP代码
$value = 1; // 表格单元格中的值
while($category=$result->fetch_assoc()){
echo "<table class='table table_list table_striped table-bordered center'>";
echo "<tr>";
echo '<td width="5%">'.'<label>'.'<input type="checkbox" class="ace"><span class="lbl">'.'</span>'.'</label>'.'</td>';
echo '<td width="10%">'.$category['id'].'</td>';
echo '<td width="20%"><img src="./images/category_img/'.$category['image_path'].'"alt="'.$category['image_path'].'"width="100px"height="100px"></td>';
echo '<td width="20%">'.$category['name'].'</td>';
echo '<td width="15%">' . ($category['status'] == 0 ? 'Activated' : ($category['status'] == 1 ? 'Forbidden' : '')) . '</td>';
echo '<td width="30%"><a href="cateedit.php?id='.$category['id'].'">Edit</a> ';
echo '<a href="Delete.php?cate=category&id='.$category['id'].'">Delete</a></td>';
echo "</tr>";
echo "</table>";
}
?>
</table>
</div>
</h3>
</div>
</body>
</html>