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

Using the combination of HTML and PHP, implement a web page where the users can upload...
Using the combination of HTML and PHP, implement a web page where the users can upload a text file, exclusively in .txt format, which contains a string of 1000 numbers, such as: 71636269561882670428252483600823257530420752963450 85861560789112949495459501737958331952853208805511 65727333001053367881220235421809751254540594752243 52584907711670556013604839586446706324415722155397 53697817977846174064955149290862569321978468622482 83972241375657056057490261407972968652414535100474 82166370484403199890008895243450658541227588666881 96983520312774506326239578318016984801869478851843 12540698747158523863050715693290963295227443043557 66896648950445244523161731856403098711121722383113 05886116467109405077541002256983155200055935729725 16427171479924442928230863465674813919123162824586 17866458359124566529476545682848912883142607690042 24219022671055626321111109370544217506941658960408 07198403850962455444362981230987879927244284909188 84580156166097919133875499200524063689912560717606 62229893423380308135336276614282806444486645238749 73167176531330624919225119674426574742355349194934 30358907296290491560440772390713810515859307960866 70172427121883998797908792274921901699720888093776 Your code should contain a PHP function that, accepting the string of 1000 numbers in input, is able to: 1) Find the 5 adjacent numbers that multiplied together...
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 text edit html Create a Web page that makes a list of your favorite movies...
using text edit html Create a Web page that makes a list of your favorite movies and a list of your favorite actors. Make one list ordered (numbered) and one list unordered (bulleted). Title your Web page - John Doe's Movies Page but use your own name (this information goes in the title tag). Also include a paragraph describing one of your favorite movies and another paragraph describing one of your favorite actors. Include two heading levels - h1 and...
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...
Write an HTML file that create the following web page. my first nested list steps of...
Write an HTML file that create the following web page. my first nested list steps of backing a cake Important notes: You should have to copy and paste the “HTML script” as your answer for this question. DON’T take screen shot for your HTML script. It must be editable script. Take a screen shot for your output web page and paste it as a part of your answer.
Using HTML: Create a Book of the Month Club Web site. The home page should describe...
Using HTML: Create a Book of the Month Club Web site. The home page should describe the current month's selection, including book title, author, publisher, ISBN, and the number of pages. Create separate Web pages for book selections in each of the last three months. Add links to the home page that opens each of the three Web pages. Save the home page as BookClub.html, and save the Web Pages for previous months using the name of the month. BOOK:...
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 an HTML file for a web page that contains the items below. Use an internal...
Write an HTML file for a web page that contains the items below. Use an internal style sheet to specify all fonts, sizes, colors, and any other aspects of the presentation. Your page should contain the following items: 1) A header with white text on dark green background (just for the header, not the entire page), in Impact font, bold, and centered. 2) Two paragraphs of text, each with dark gray text in Tahoma font, on a light blue background,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT