-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsearch.php
67 lines (67 loc) · 2.51 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
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>検索結果</title>
<link rel=stylesheet href="main.css" type="text/css" charset="utf-8" />
<script src="jq/jquery-3.2.1.js" type="text/javascript"></script>
<script src="jq/jquery.tablesorter.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#booksTable").tablesorter();
}
);
</script>
</head>
<body>
<?php
try{
require_once 'DbManager.php';
$db = getDb();
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
}catch(PDOException $Exception){
die('接続エラー:' .$Exception->getMessage());
}
try{
if(empty($_GET['keyword'])) throw new Exception("検索キーワードが入力されていません");
$char = $_GET['keyword'];
$sql = "SELECT * FROM 一般 WHERE タイトル LIKE '%$char%' or 著者 LIKE '%$char%' or イラスト LIKE '%$char%' or 出版 LIKE '%$char%'";
$stmh = $db->prepare($sql);
$stmh->execute();
}catch(Exception $Exception){
echo '検索エラー:' .$Exception->getMessage();
die();
}
?>
<h1><?php echo "検索結果: ".$_GET[keyword]?></h1>
<table class="books">
<thead>
<tr>
<th>タイトル</th>
<th>著者</th>
<th>イラスト</th>
<th>出版</th>
<th>種別</th>
</tr>
</thead>
<tbody>
<?php
while($row = $stmh->fetch(PDO::FETCH_ASSOC)){
?>
<tr>
<td><a href="edit.php?id=<?=htmlspecialchars($row['蔵書番号'])?>"><?=htmlspecialchars($row['タイトル'])?></a></th>
<td><a href="refine.php?column=著者&text=<?=htmlspecialchars($row['著者'])?>"><?=htmlspecialchars($row['著者'])?></a></th>
<td><a href="refine.php?column=イラスト&text=<?=htmlspecialchars($row['イラスト'])?>"><?=htmlspecialchars($row['イラスト'])?></a></th>
<td><a href="refine.php?column=出版&text=<?=htmlspecialchars($row['出版'])?>"><?=htmlspecialchars($row['出版'])?></a></th>
<td><a href="refine.php?column=種別&text=<?=htmlspecialchars($row['種別'])?>"><?=htmlspecialchars($row['種別'])?></a></th>
</tr>
<?php
}
$db = null;
?>
</tbody>
</table>
<a href="./">一覧に戻る</a>
</body>
</html>