I want to create a list of books that I can return as a valid JSON output. There should only be one JSON output that outputs a list of books. I have this at the moment but the problem is only the last book of the while loop is added to the list Book which is what I want to return.
//Return each book found given search.
while(list($book_id, $title, $authors, $description, $price) = mysqli_fetch_row($search)){
$thisBook = array("book_id"=>$book_id,"title"=>$title,"authors"=>$authors,"description"=>$description,"price"=>$price);
$Book = array();
$Book[] = $thisBook;
}
//JSON Return
$success = TRUE;
$message = "Success";
$output = $Book;
echo json_encode($output);
How could I do this? Thanks