Lab 11 - PHP with MySQL

Goals

  1. To gain experience using PHP with MySQL
  2. To create multipage PHP/HTML/MySQL web interfaces to a database
  3. To interact with MySQL using an HTML form and PHP

Steps

Step 1 - Simple Queries

In your web directory you will find a directory "Lab11". In it you will find today's lab examples.

First consider "countrylistsmall.php". The code is here: countrylistsmall.php


SmallCountries.png

As you can see, the code simplydoes the appropriate query, and extracts the displays the results in a table.

Also in the directory is "countrygovtypes.php". See the code: countrygovtypes.php. Try it out.

Step 2 - Menu

Next we wish to make a menu page to allow us to select which query we want to perform.

Here is a simple menu in countrymenu.php

Look at the code, and figure out what makes it tick.

Step 3 - Write some searches

By adapting the previous searches, write new code to do the following. Add each to the menu. Option 4 is only required by those who have completed Data Structures.

  1. "Long Life " search: List the countries with a life expectancy of greater than 70, in decending order.
  2. "High Density: search: List the name, continent, region, population, and square miles for every country that has more than 100 people per square mile.
  3. "Big City" search: List the city name, city population, and country code of every city that has greater than 10 million people. (use a different table)
  4. "City 20% of Country" search: List the city name, country name, city population, of every city that has more then 20% of the population in it's country. (Requires a join)
Step 4 - User Input

First consider some code that allows the user to give input in to the search:

  1. Review the code in countrysearchselect.html. This allows the user to select a search type, and then enter the search parameters.
  2. Review the code in countrylistmatches.php. This processes the entries made in countrysearchselect.html.
Modify this code to do the following. Number for is only for those who have completed data structures:

  1. List all countries names, continent, and year founded in a given region (entered by user)
  2. List all countries that are less than a certain number of years old. (Or give a low and high range)
  3. Given a government type, list the Countries names, continent, and region
  4. Given a percent, find and list the city name, country name, city population, of every city that has more then that % of the population in it's country.
Step 5 - menu linkage

Modify the both countrysearchselect.html and countrylistmatches.phpso that they have a button that returns to the main menu.

Step 6 - Turn it in

Simply turn in the URL of you main menu!

Topic attachments
I Attachment Action Size Date Who Comment
Pngpng SmallCountries.png manage 65.7 K 2013-11-22 - 14:47 JimSkon  
Topic revision: r1 - 2013-11-22 - JimSkon
 
This site is powered by the TWiki collaboration platformCopyright &© by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback