Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

=+Where does the focus of labor relations lie? Is it collective

Answered: 1 week ago

Question

=+With whom does the firm have to negotiate?

Answered: 1 week ago