Question

Assignment 7 This is a two-part assignment. Students will create and submit 3 scripts. Here are...

Assignment 7 This is a two-part assignment. Students will create and submit 3 scripts.

Here are the instructions: Before You need to Import the books_sc database via phpMyAdmin Script

1 Create a php file to connect to the books_sc database. You can name this file connect.php. This separate file will be ‘included’ in the other scripts, script 2 and script 2 Script 2 (25 points – to receive these points, you need to have the connect.php file created and submitted)

1. Connect to the books_sc database by including the connect.php 2. Create a query to select all books from the books table. Perform the necessary steps to obtain all records from the record set 3. Displayed the retrieved records using a foreach loop. Display the data in an organized manner. Make use of the main.css file we’ve been using so far, or have your own. Remember, we are working towards a term project Script 3 (25 points – to receive these points, you need to have the connect.php file created and submitted)

1. Connect to the books_sc database by including the connect.php 2. Create a query to select books from the books table with a price less than 30 dollars. Perform the necessary steps to obtain all records from the record set 3. Display the data in an organized manner. Make use of the main.css file we’ve been using so far, or have your own. Remember, we are working towards a term project

books_sc-1.sql

Homework Answers

Answer #1

connect.php file

You need to change the servername, username, password and dbname as per the actual ones.

<?php

// replace these values with your values
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "books_sc";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection, exit if error
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}

?>

This file can be inclused in subsequent scripts to get connect to the database.

script2.php

Assuming the structure of the books table to be

books (isbn, author, title, price, catID)

<?php include 'connect.php';

// sql statement to select all books
$sql = "SELECT * FROM books";

// execute query
$result = $conn->query($sql);

// constructing a table
echo "<table border=1><thead><th>ISBN</th><th>Author</th><th>Title</th><th>Price</th><th>Cat Id</th></thead>";

// create table rows for each row
foreach ($result as $row) {
        echo "<tr><td>" . $row["isbn"] . "</td>";
        echo "<td>" . $row["author"] . "</td>";
        echo "<td>" . $row["title"] . "</td>";
        echo "<td>" . $row["price"] . "</td>";
        echo "<td>" . $row["catID"] . "</td></tr>";
}

// close the table tag
echo "</table>";

// close database connection
$conn->close();
?>

Find the sample output below.

Script3.php

<?php include 'connect.php';

// sql statement to select books priced less than 30$
$sql = "SELECT * FROM books WHERE price < 30";

// execute query
$result = $conn->query($sql);

// constructing a table
echo "<table border=1><thead><th>ISBN</th><th>Author</th><th>Title</th><th>Price</th><th>Cat Id</th></thead>";

// create table rows for each row
foreach ($result as $row) {
        echo "<tr><td>" . $row["isbn"] . "</td>";
        echo "<td>" . $row["author"] . "</td>";
        echo "<td>" . $row["title"] . "</td>";
        echo "<td>" . $row["price"] . "</td>";
        echo "<td>" . $row["catID"] . "</td></tr>";
}

// close the table tag
echo "</table>";

// close database connection
$conn->close();
?>

Find the sample output below.

Thanks & Regards.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
A. Create a PowerShell script named “restore.ps1” within the “Requirements2” folder. For the first line, create...
A. Create a PowerShell script named “restore.ps1” within the “Requirements2” folder. For the first line, create a comment and include your first and last name along with your student ID. Note: The remainder of this task shall be completed within the same script file, “restore.ps1.” B. Write a single script within the “restore.ps1” file that performs all of the following functions without user interaction: 1. Create an Active Directory organizational unit (OU) named “finance.” 2. Import the financePersonnel.csv file (found...
This is C++ Note, for part 2 of this assignment, you DO NOT NEED to use...
This is C++ Note, for part 2 of this assignment, you DO NOT NEED to use arrays or vectors. All changes, calculations, etc should be performed in place ( in the file). You may need one or two structures that temporary hold data needed to be displayed, changed, etc. Part 2: Binary Files Write a program that uses a structure to store the following inventory data in a file: The data can be either read from a text file or...
PLEASE DO QUICK LINUX ASSIGNMENT PLEASE ILL THUMBS UP You need to paste the command and...
PLEASE DO QUICK LINUX ASSIGNMENT PLEASE ILL THUMBS UP You need to paste the command and the output in a word document and submit it. Part1: 1. Log in to Linux using your user account name and password. 2. If you logged in using a graphical login screen, open a terminal window by clicking on the icon in the lower left corner of the desktop to open the main menu, then selecting System Tools, then Terminal. A terminal window opens....
My assignment is listed below. I already have the code complete, but I cannot figure out...
My assignment is listed below. I already have the code complete, but I cannot figure out how to complete this portion: You must create a makefile to compile and build your program. I can't figure out if I need to create a makefile, and if I do, what commands do I use for that? Create a  ContactInfo class that contains the following member variables: name age phoneNumber The ContactInfo class should have a default constructor that sets name = "", phoneNumber...
Hello! I'm getting this assignment wrong according to the cengage software. The code looks right to...
Hello! I'm getting this assignment wrong according to the cengage software. The code looks right to me but apparently it is not. May someone please take a look at it and let me know what I'm doing wrong. I just can't seem to find the error. I'm attaching the question below and below that I will attach my code. I appreciate any help you could provide. The book is: HTML5, CSS3, and JavaScript, 6th edition, Bundle Thanks QUESTION: General Flex...
PHP calculator problem Create a calculator class that will add, subtract, multiply, and divide two numbers....
PHP calculator problem Create a calculator class that will add, subtract, multiply, and divide two numbers. It will have a method that will accept three arguments consisting of a string and two numbers example ("+", 4, 5) where the string is the operator and the numbers are what will be used in the calculation. It doesn't need an HTML form, all the arguments are put in through the method. The class must check for a correct operator (+,*,-,/), and a...
Overview Your assignment is to complete a wireless network design for a small company. You will...
Overview Your assignment is to complete a wireless network design for a small company. You will place a number of network elements on the diagram and label them appropriately. A network diagram is important to communicate the design features of a network between network administrators, system administrators and cyber-security analysts. It helps to create a shared mental model between these different technologists, yet each will have their own perspective on what is important to have documented on the diagram. Please...
The assignment summary sheets will be submitted week 14 with Test 3. You are to personally...
The assignment summary sheets will be submitted week 14 with Test 3. You are to personally experience the power and satisfaction of developing these skills firsthand and to reflect and write about this experience. Over the years, many students have shared amazingly rewarding experiences as they worked on these skills. The assignment will be evaluated and be weighted as 5% of your final mark (together, they are worth 20% of your mark for Test 3, which is worth 25% of...
CASA3: Draft Problem Statement for Report with Preliminary Scholarly Sources List CASA3 has 2 parts but...
CASA3: Draft Problem Statement for Report with Preliminary Scholarly Sources List CASA3 has 2 parts but is to be submitted as one document. Part A: Draft problem statement for report Part B: Preliminary scholarly sources list Here are some points to consider: Part A:. Management Problem Statement: Revisit, improve and enhance your CASA1- Management Problem Statement Link to the Functions of Management (planning, leading, organising and controlling) Clearly indicate a management problem or potential problem Balance of facts from the...
Using the model proposed by Lafley and Charan, analyze how Apigee was able to drive innovation....
Using the model proposed by Lafley and Charan, analyze how Apigee was able to drive innovation. case:    W17400 APIGEE: PEOPLE MANAGEMENT PRACTICES AND THE CHALLENGE OF GROWTH Ranjeet Nambudiri, S. Ramnarayan, and Catherine Xavier wrote this case solely to provide material for class discussion. The authors do not intend to illustrate either effective or ineffective handling of a managerial situation. The authors may have disguised certain names and other identifying information to protect confidentiality. This publication may not be...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT