Question

In: Computer Science

Create a web page using PHP and HTML that contains a list of movie names available...

Create a web page using PHP and HTML that contains a list of movie names available for rent (at least 10 movies), so that each time you visit the home page, you see a different order of movies in the list. The movie names are required.

2) The rental price for each movie ranges between $1.99 to $7.99.

• Create an associative array with a code for the movie as the key (e.g., movie1, movie2, etc.) and the associated rental price as the value. Display the array using the print_r() function.

• Sort the array according to the rental price in ascending order. Display the array again using the print_r() function.

• Calculate and display the average rental price for a movie.

• Find and display the two highest and two lowest rental prices.

Display these results on the same page. Again, display appropriate warning/error messages as needed.

Solutions

Expert Solution

Hi,

Save the following code in .php file. Most of the code is readable and well commented for better understanding.

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Movies For Rent</title>

</head>

<body>
<?php
/*
Create an associative array with a code for the movie as the key (e.g., movie1, movie2, etc.) and the associated rental price as the value. Display the array using the print_r() function.
*/
        /*Movies Associate Array*/
        $movies = array(
        "movie1" => 7.45,
        "movie2" => 3.50,
        "movie3" => 2.50,
        "movie4" => 4.25,
        "movie5" => 1.50,
        "movie6" => 6.00,
        "movie7" => 2.70,
        "movie8" => 5.75,
        "movie9" => 6.10,
        "movie10" => 3.80,
        "movie11" => 2.75
        );

        /*Printing as it is using print_r and true for pretty print*/
        echo "<h4>Movies</h4>";
        echo "<pre>" . print_r($movies, true) . "</pre>";
        ?>
<hr>
<?php
/*
Sort the array according to the rental price in ascending order. Display the array again using the print_r() function.
*/
        /*Sorting by value [price] using """asort"""*/
        asort($movies);

        /*Printing after sorting using print_r and true for pretty print*/
        echo "<h4>Movies sorted by rental prices</h4>";
        echo "<pre>" . print_r($movies, true) . "</pre>";
        ?>
<hr>
<?php
        /*Calculate and display the average rental price for a movie.*/
        $total_value_of_movies = array_sum($movies); //sum of all values in the associated array
        $movies_count = count($movies);
        $average = $total_value_of_movies / $movies_count;

        echo "<p>Average Movie Rental Price: <strong>" . round($average, 2) . "$</strong></p>"

        ?>
<hr>
<?php
/*
Find and display the two highest and two lowest rental prices.
Display these results on the same page.
*/
        $rental_prices = array_values($movies); //getting only rental prices that too already sorted
//Displaying last two values of the prices array
        echo "<p>Top Two Highest Rental Prices: <strong>" . $rental_prices[$movies_count - 1] . ", " . $rental_prices[$movies_count - 2] . "</strong></p>";

        echo "<br>"; //for new line

//Displaying first two values of the prices array
        echo "<p>Top Two Lowest Rental Prices: <strong>" . $rental_prices[0] . ", " . $rental_prices[1] . "</strong></p>";
        ?>
</body>
</html>

Hope this helps.

All the best.


Related Solutions

Create a web page using PHP that allows the users to create an account (a username...
Create a web page using PHP that allows the users to create an account (a username and a password). There should be a login page that allows users to create an account by entering their preferred username and password. The same page should also let users login if they already have an account. If a user is logged in successfully , they should be able to enter a comment and also read the comments entered by others previously.
Using a combination of HTML/PHP, implement a web page where the users can upload a text...
Using a combination of HTML/PHP, implement a web page where the users can upload a text file, exclusively in .txt format, which contains a string of 400 numbers, such as: 71636269561882670428 85861560789112949495 65727333001053367881 52584907711670556013 53697817977846174064 83972241375657056057 82166370484403199890 96983520312774506326 12540698747158523863 66896648950445244523 05886116467109405077 16427171479924442928 17866458359124566529 24219022671055626321 07198403850962455444 84580156166097919133 62229893423380308135 73167176531330624919 30358907296290491560 70172427121883998797 Your code should contain a PHP function that, accepting the string of 400 numbers in input, is able to find the greatest product of four adjacent numbers in all the...
Create a Web Page Using HTML, CSS, JS, jQuery • Create a web profile, including any...
Create a Web Page Using HTML, CSS, JS, jQuery • Create a web profile, including any of the following: • Your hobbies, likes/dislikes, career aspirations, dream job, favorite animals/ pets, favorite superhero, etc. • You do not have to share personal information that you are uncomfortable with sharing. Follow these guidelines when creating your page: • Include at least one heading (h1, h2, etc.) in your web page. • Provide a quote from a book, movie, etc. • Include at...
Create an HTML page that contains a three-level nesting list (you may choose the type of...
Create an HTML page that contains a three-level nesting list (you may choose the type of the list you want to use). One item on each level. Use the three attached images as the content of each of the three list items. use any random image name located in the default directory
I already have a database in phpMyAdmin and need to create an html/php "SEARCH" page to...
I already have a database in phpMyAdmin and need to create an html/php "SEARCH" page to retrieve the information from the database on to my localhost. Please post a php/html code that will create a search page and return the data from my phpmyadmin database. The 3 items I have on the database are first_name, last_name and birth_day.
write php code for buying and selling web using sql, javascript ,html ,css style
write php code for buying and selling web using sql, javascript ,html ,css style
Create a web page that contains a simple math test. The page should have the following...
Create a web page that contains a simple math test. The page should have the following arithmetic problems. Add a button under each problem which, when clicked, will display a prompt for the user to enter the answer. Add a swcond button which, when clicked, will check to see if the user's answer is correct. The output should be either "correct" or "incorrect" displayed in an alert box. 1. 5+9= 2. 4*6= 3. 25-14= 4. 48/3= 5. 26%6=
PHP Question - Subject: PHP File Handling and Uploads INSTRUCTIONS: Objective: • Create a sticky HTML...
PHP Question - Subject: PHP File Handling and Uploads INSTRUCTIONS: Objective: • Create a sticky HTML form. • Submit form for processing. • Sanitize and validate form data. • Upload a profile image. • Add a record to a text file. • Display form results with content from another text file and the uploaded image. Description: This assignment deals with file management. It requires the use of 3 new files and 1 new directory. You will create the new file-uploads.php...
PHP Question - Subject: PHP File Handling and Uploads INSTRUCTIONS: Objective: • Create a sticky HTML...
PHP Question - Subject: PHP File Handling and Uploads INSTRUCTIONS: Objective: • Create a sticky HTML form. • Submit form for processing. • Sanitize and validate form data. • Upload a profile image. • Add a record to a text file. • Display form results with content from another text file and the uploaded image. Description: This assignment deals with file management. It requires the use of 3 new files and 1 new directory. You will create the new file-uploads.php...
1. An HTML document that’s generated by a web application is a ________________________ web page. 2....
1. An HTML document that’s generated by a web application is a ________________________ web page. 2. An easy way to log the progress of an application in Chrome’s Console panel is to insert __________________ methods at critical points in the code. 3. The childNodes property of a DOM object returns a/an ______________________ of the child nodes for that object. 4. The ___________________ method of an array can be used to concatenate the elements of the array into a single string.​...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT