This repository has been archived by the owner on Jul 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
search.php
184 lines (142 loc) · 7.45 KB
/
search.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
<?php
/**
* 检索功能
*/
require "common/function.php";
//获取关键词
$keywords_string = '';
if(isset($_GET["d_s"])&&$_GET["d_s"] != ''){
$keywords_string = $_GET["d_s"];
}
else if(isset($_GET["m_s"])&&$_GET["m_s"] != ''){
$keywords_string = $_GET["m_s"];
}
if($keywords_string!=''){
//分词
$keywords = explode(" ",$keywords_string);
}
//组合搜索SQL语句
$search_book_sql = "select * from `book_list` where ";
for($i=0;$i<sizeof($keywords);$i++){
$search_book_sql .= "`name` like '%".$keywords[$i]."%' and ";
}
$search_book_sql .= " `publish` = '1' order by `time` desc";
$search_article_sql = "select * from `article` where ";
for($i=0;$i<sizeof($keywords);$i++){
$search_article_sql .= "`title` like '%".$keywords[$i]."%' and ";
}
$search_article_sql .= "`publish` = '1' order by `time` desc";
//echo $search_article_sql;
//echo $search_book_sql;
$book_list = @select_more_data($search_book_sql);
//获取额外内容
for ($i = 0; $i < sizeof($book_list); $i++) {
//获取书籍信息
$book_list[$i]["book_info"] = select_data("select * from `book_list` where `ID` = '" . $book_list[$i]["ID"] . "'");
//获取作者信息
$book_list[$i]["author_info"] = select_data("select * from `user_account` where `ID` = '" . $book_list[$i]["author"] . "'");
//获取该文集的最新更新文章的更新时间
$book_list[$i]["update_time"] = select_data("select `time` from `article` where `book` = '" . $book_list[$i]["ID"] . "' and `publish` = 1 order by `time` desc")["time"];
}
$article_list = @select_more_data($search_article_sql);
//获取额外内容
for ($i = 0; $i < sizeof($article_list); $i++) {
//获取所属文集信息
$article_list[$i]["book_info"] = select_data("select * from `book_list` where `ID` = '" . $article_list[$i]["book"] . "'");
//获取作者信息
$article_list[$i]["author_info"] = select_data("select * from `user_account` where `ID` = '" . $article_list[$i]["author"] . "'");
}
require "theme/model/head.html";
require "theme/model/menu.html";
?>
<section class="section" style="overflow: hidden;">
<div class="container">
<div class="container" style="margin-bottom: 20px">
<h2>"<?php echo $keywords_string; ?>" 的书籍搜索结果</h2>
</div>
<div class="row listings-grid">
<?php for ($i = 0; $i < sizeof($book_list); $i++) { ?>
<!--第<?php echo $i; ?>个热门-->
<div class="col-sm-4 col-md-4">
<div class="listings-grid__item">
<a href="topic.php?cid=<?php echo $book_list[$i]["ID"]; ?>">
<div class="listings-grid__main">
<img src="<?php echo $book_list[$i]["cover"]; ?>"
alt="<?php echo $book_list[$i]["name"]; ?>">
<div class="listings-grid__price">
最近更新于<?php echo date("Y年m月d日", strtotime($book_list[$i]["update_time"])); ?></div>
</div>
<div class="listings-grid__body">
<small><?php echo $book_list[$i]["author_info"]["nick_name"] ?> 著</small>
<h5><?php echo $book_list[$i]["name"]; ?></h5>
</div>
<ul class="listings-grid__attrs">
<li>
<div class="rmd-rate"
data-rate-value="<?php echo $book_list[$i]["book_info"]["star"] ?>"
data-rate-readonly="true"></div>
</li>
<li><?php echo $book_list[$i]["book_info"]["star"] ?>分</li>
<!--<li><i class="listings-grid__icon listings-grid__icon--parking"></i> 02</li>-->
</ul>
</a>
<div class="actions listings-grid__favorite">
<div class="actions__toggle" title="收藏">
<input type="checkbox">
<i class="zmdi zmdi-star-outline"></i>
<i class="zmdi zmdi-star"></i>
</div>
</div>
</div>
</div>
<?php } ?>
</div>
<!--********************************输出主要内容*****************************************-->
<div class="row">
<div class="col-md-8 col-sm-7">
<div class="container" style="margin-bottom: 20px">
<h2>"<?php echo $keywords_string; ?>" 的文章搜索结果</h2>
</div>
<!-- 每页10条文章 -->
<?php for ($i = 0; $i < sizeof($article_list); $i++) { ?>
<a href="article.php?id=<?php echo $article_list[$i]["ID"] ?>">
<article class="card">
<?php if ($article_list[$i]["image"] != '') { ?>
<!-- 文章图片 -->
<div class="card__img" style="max-height: 300px;overflow: hidden;">
<img src="<?php echo $article_list[$i]["image"] ?>"
alt="<?php echo $article_list[$i]["title"] ?>">
</div>
<?php } ?>
<div class="article_header">
<h2><?php echo $article_list[$i]["title"] ?></h2>
</div>
<div class="article_body">
<p><?php echo $article_list[$i]["description"] ?></p>
<button class="btn btn-sm btn-primary">阅读更多 <i class="zmdi zmdi-open-in-new"></i></button>
</div>
<div class="article_info">
<p>作者:<?php echo $article_list[$i]["author_info"]["nick_name"] ?></p>
<p>发表于:<?php echo date("Y年m月d日", strtotime($article_list[$i]["time"])); ?></p>
<p>该章收录于《<?php echo $article_list[$i]["book_info"]["name"]; ?>》篇目</p>
</div>
</article>
</a>
<?php } ?>
</div>
<!--********************************右侧栏*****************************************-->
<aside class="col-md-4 col-sm-5">
<div class="container" style="margin-bottom: 20px;width: 100%;">
<h2> </h2>
</div>
<?php require "theme/model/https.php"; ?>
<?php if (!isset($_COOKIE["use_cookies"])) {
require "theme/model/cookie.html";
} ?>
</aside>
</div>
</div>
</section>
<?php
require "theme/model/footer.html";
?>