Question: My code is as follows. I need help completing it as I've been stuck for three days now :( improve the books.php so it pulls

My code is as follows. I need help completing it as I've been stuck for three days now :(

class Book {

public $title;

public $author;

public $blurbs;

public $image_location;

public $price;

function __construct($title, $author, $blurbs, $image_location, $price){

$this->title = $title;

$this->author = $author;

$this->blurbs = $blurbs;

$this->image_location = $image_location;

$this->price = $price;

}

}

$books = array(

new Book('Learning PHP, MYSQL & Javascript', 'Robin Nixon', 'A step by step guide to creating dynamic websites.', 'assets\imgs\learningphp.jpg', 60.00),

new Book('We Love Dogs!', 'Vinny Garofalo', 'The greatest dog book ever', 'assets\imgs\dog.jpg', 50.00),

new Book('Fun Book', 'Vinny Garofalo', 'This book is pure fun!', 'assets\imgs\funbook.jpg', 50.00),

new Book('Learning Python', 'Mark Lutz', 'Powerful Object-Oriented Programming', 'assets\imgs\learningpython.jpg', 49.00),

new Book('HTML and CSS', 'Joe Casabona', 'Design and build webpages.', 'assets\imgs\htmlcss.jpg', 35.00),

new Book('The American Heritage Dictionary', 'No Author', 'The English Language', 'assets\imgs\dictionary.jpg', 55.00)

);

?>

improve the books.php so it pulls book information from the database instead of array of book objects.

Delete the code that creates an array of book objects. Keep the tags and Book class!

In the books code above, add a require_once call to login.php.

Write a try catch to create a $pdo variable in the code.

Write a query to pull all the records from the books table. (table is called books)

Store the query in a variable.

Run the query against $pdo and store the result in a variable.

Write a while loop that loops through each row in the query result. Instead of echoing each parameter, assign each to a variable.

Make sure you use the htmlspecialchars function to avoid unexpected results.

The columns should include: id, title, author, description (blurb), image path, price.

Create a book object (using the Book class) and add it to an array of books.

Do this inside the while loop and use the variables you created from the database row. Make the books array an associative array indexed by the BookID from the database.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!