Wyszukiwanie

This commit is contained in:
krzysiej
2018-06-28 09:19:37 +02:00
parent 7b0eb7769f
commit 91af53fc45
2 changed files with 7 additions and 4 deletions

View File

@@ -3,18 +3,21 @@ include 'vendor/autoload.php';
set_time_limit(-1);
$db = new SQLite3('data.db');
if (isset($_GET['category']) && strlen($_GET['category'])) {
$stmt = $db->prepare('SELECT * FROM book WHERE category_slug = :category_slug');
$stmt->bindValue(':category_slug', $_GET['category'], SQLITE3_TEXT);
} elseif (isset($_POST['search']) && isset($_POST['title']) && !empty($_POST['title'])) {
$stmt = $db->prepare('SELECT * FROM book WHERE title like :search');
$stmt->bindValue(':search', '%' . $_POST['title'] . '%', SQLITE3_TEXT);
} else {
$stmt = $db->prepare('SELECT * FROM book ');
}
//$stmt->bindValue(':nid', $bookData['nid'], SQLITE3_INTEGER);
$result = $stmt->execute();
echo "<form method='POST'><input type='text' name='title' value='" . ($_POST['title'] ?? '') . "' /><button type='submit' name='search'>Search</button><a href='/'>Clear</a></form>";
echo '<table style="width: 100%">';
print('<tr> <th>id</th><th>nid</th><th>Title</th><th>Category</th><th>Publish date</th><th>Pages</th><th>Votes</th><th>Rating</th> <th>Pdf</th> <th>Epub</th> <th>Mobi</th> <th>Code</th> </tr>');
while ($resultArray = $result->fetchArray(SQLITE3_ASSOC)) {