This repository was archived by the owner on Mar 6, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.php
More file actions
145 lines (133 loc) · 6.44 KB
/
search.php
File metadata and controls
145 lines (133 loc) · 6.44 KB
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
<?php
session_start();
include 'includes/db.php';
include 'includes/functions.php';
/** @var mysqli $conn */
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit();
}
$search_results = [];
$search_query = "";
if (isset($_GET['query'])) {
$search_query = trim($_GET['query']);
$search_term = "%" . $search_query . "%";
$stmt = $conn->prepare("SELECT id, title, author, isbn, status, image FROM books WHERE title LIKE ? OR author LIKE ?");
$stmt->bind_param("ss", $search_term, $search_term);
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
$search_results[] = $row;
}
$stmt->close();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Search Books | Library System</title>
<link rel="stylesheet" href="assets/css/bootstrap.min.css">
<style>
body { background-color: #f4f7f6; }
.sidebar { min-height: 100vh; background-color: #f8f9fa; border-right: 1px solid #dee2e6; padding-top: 20px; position: fixed; width: 16.666667%; }
.main-content { margin-left: 16.666667%; }
.book-thumb { width: 50px; height: 75px; object-fit: cover; border-radius: 4px; border: 1px solid #ddd; }
</style>
</head>
<body>
<div class="container-fluid">
<div class="row">
<nav class="col-md-2 d-none d-md-block sidebar">
<div class="text-center mb-4">
<h5 class="fw-bold text-success text-wrap px-2">Library Management System</h5>
</div>
<div class="d-grid gap-2 px-3">
<a href="Home.php" class="btn btn-outline-success">Home</a>
<a href="dashboard.php" class="btn btn-outline-success">My Dashboard</a>
<a href="search.php" class="btn btn-outline-success active">Search Books</a>
<hr>
<a href="logout.php" class="btn btn-danger">Logout</a>
</div>
</nav>
<main class="col-md-10 ms-sm-auto px-md-4 main-content">
<div class="pt-3 pb-2 mb-3 border-bottom">
<h2>Find a Book</h2>
</div>
<div class="card shadow-sm mb-4">
<div class="card-body">
<form action="search.php" method="GET" class="row g-3">
<div class="col-md-10">
<input type="text" name="query" class="form-control"
placeholder="Search by title or author..."
value="<?php echo e($search_query); ?>">
</div>
<div class="col-md-2">
<button type="submit" class="btn btn-success w-100">Search</button>
</div>
</form>
</div>
</div>
<div class="card shadow-sm">
<div class="card-body">
<div class="table-responsive">
<table class="table table-hover align-middle">
<thead class="table-dark">
<tr>
<th>Cover</th>
<th>Title</th>
<th>Author</th>
<th>ISBN</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php if (!empty($search_results)): ?>
<?php foreach ($search_results as $book): ?>
<tr>
<td>
<img src="image/<?php echo e($book['image']); ?>"
class="book-thumb"
alt="Cover"
onerror="this.src='https://via.placeholder.com/50x75?text=NA'">
</td>
<td>
<div class="fw-bold"><?php echo e($book['title']); ?></div>
</td>
<td><?php echo e($book['author']); ?></td>
<td><?php echo e($book['isbn']); ?></td>
<td>
<span class="badge <?php echo ($book['status'] == 'Available') ? 'bg-success' : 'bg-danger'; ?>">
<?php echo e($book['status']); ?>
</span>
</td>
<td>
<?php if ($book['status'] == 'Available'): ?>
<a href="borrow.php?book_id=<?php echo $book['id']; ?>" class="btn btn-sm btn-primary">Borrow</a>
<?php else: ?>
<button class="btn btn-sm btn-secondary" disabled>Unavailable</button>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
<?php elseif (isset($_GET['query'])): ?>
<tr>
<td colspan="6" class="text-center py-4 text-muted">No books found matching "<?php echo e($search_query); ?>"</td>
</tr>
<?php else: ?>
<tr>
<td colspan="6" class="text-center py-4 text-muted">Enter a book title or author to begin searching.</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
</main>
</div>
</div>
<script src="assets/js/bootstrap.bundle.min.js"></script>
</body>
</html>