-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbooks.php
executable file
·36 lines (28 loc) · 998 Bytes
/
books.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
<?php
require_once('config.php');
session_start();
$dbh = connect();
$return[0] = array("book_id" => false, "title" => false,"authors" => false, "description" => false, "price" => false);
$title = $_GET['title'];
$authors = $_GET['authors'];
$start = 0;
$length = NULL;
if (!$_GET['start'] == ""){
$start = $_GET['start'];
}
if (!$_GET['length'] == ""){
$length = $_GET['length'];
}
$query = $dbh->prepare("SELECT id, title, authors, description, price FROM books WHERE title LIKE '%".$title."%' AND authors LIKE '%".$authors."%'");
if($query->execute()){
$row = $query->fetchAll();
$count = $query->rowCount();
if($length == NULL){
$length = $count;
}
for($i = 0; $i < $length-$start; $i++){
$return[$i] = array("book_id" => $row[$start+$i]['id'] , "title" => $row[$start+$i]['title'],"authors" => $row[$start+$i]['authors'], "description" => $row[$start+$i]['description'], "price" => $row[$start+$i]['price']);
}
}
exit(json_encode($return));
?>