Obsługa kategorii, filtrowanie.

This commit is contained in:
krzysiej
2018-06-27 15:36:53 +02:00
parent f4c4d029e6
commit 7b0eb7769f
2 changed files with 8 additions and 6 deletions

Binary file not shown.

View File

@@ -6,16 +6,18 @@ set_time_limit(-1);
$db = new SQLite3('data.db');
$stmt = $db->prepare('SELECT * FROM book ');
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);
} else {
$stmt = $db->prepare('SELECT * FROM book ');
}
//$stmt->bindValue(':nid', $bookData['nid'], SQLITE3_INTEGER);
$result = $stmt->execute();
echo '<pre>';
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)) {
// print_r($resultArray);
$pdfUrl = 'books/' . $resultArray['nid'] . '/' . $resultArray['nid'] . '.pdf';
$epubUrl = 'books/' . $resultArray['nid'] . '/' . $resultArray['nid'] . '.epub';
@@ -25,8 +27,8 @@ while ($resultArray = $result->fetchArray(SQLITE3_ASSOC)) {
$codeId = $found[0];
$codeUrl = 'books/' . $codeId . '/' . $codeId . '.zip';
}
printf('<tr> <td>%d</td><td>%d</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%d</td><td>%.1f</td> <td>%s</td><td>%s</td><td>%s</td><td>%s</td> </tr>',
$resultArray['id'], $resultArray['nid'], $resultArray['title'], $resultArray['category'], $resultArray['datepublished'], $resultArray['numberofpages'], $resultArray['reviewCount'], $resultArray['ratingValue'],
printf('<tr> <td>%d</td><td>%d</td><td><a href="http://packtpub.com%s">%s</a></td><td><a href="?category=%s">%s</a></td><td>%s</td><td>%s</td><td>%d</td><td>%.1f</td> <td>%s</td><td>%s</td><td>%s</td><td>%s</td> </tr>',
$resultArray['id'], $resultArray['nid'], $resultArray['url'], $resultArray['title'], $resultArray['category_slug'], $resultArray['category'], $resultArray['datepublished'], $resultArray['numberofpages'], $resultArray['reviewCount'], $resultArray['ratingValue'],
is_file($pdfUrl) ? "<a href='{$pdfUrl}'>pdf</a>" : (strlen($resultArray['pdf']) ? 'nie pobrano' : ''),
is_file($epubUrl) ? "<a href='{$epubUrl}'>epub</a>" : (strlen($resultArray['epub']) ? 'nie pobrano' : ''),
is_file($mobiUrl) ? "<a href='{$mobiUrl}'>mobi</a>" : (strlen($resultArray['mobi']) ? 'nie pobrano' : ''),