Due: 10 Feb 2012, 11:59pmAbstract
Given an array of data, use PHP to display an HTML page with information in a table.Assignment
In this assignment you will write a PHP file named index.php that will take a static set of data and translate it into an HTML table. The code below should be copied exactly into your homework file:
$difficulty_names = array( 1 => "Easy", 2 => "Hard", 3 => "Insane" ); $testchambers = array ( 10 => array( "name" => "The tenth", "objects" => array(), "difficulty" => 1 ), 11 => array( "name" => "A harder test chamber", "objects" => array( "toxic water", "high energy pellet" ), "difficulty" => 2 ), 12 => array( "name" => "Has three things!!", "objects" => array( "cube dispenser", "falling cube", "portal gun" ), "difficulty" => 3 ) );
You should make use of PHP's foreach loops to generate the output rather than hard-coding the resulting HTML. Assignments that hard-code the result will be penalized harshly. The idea is that, if there were more elements in the array, the code you've written should generate more table data.
Your table should have the following columns, with data generated from the $testchambers array and appropriate headings:
You should use the $difficulty_names array to print out the values in the difficulty column.
A table can be constructed in HTML using the table, tr, th, and td tags. The table tags specify the beginning and end of the table. Within those tags, tr tags specify a row, and within those th tags describe header cells and td tags describe data cells. An example follows:
<table id="example"> <tr> <th>Table heading 1</th> <th>Table heading 2</th> <th>Table heading 3</th> </tr> <tr> <td>Row 1, Cell 1</td> <td>Row 1, Cell 2</td> <td>Row 1, Cell 3</td> </tr> <tr> <td>Row 2, Cell 1</td> <td>Row 2, Cell 2</td> <td>Row 2, Cell 3</td> </tr> </table>
This generates the following table:
|Table heading 1||Table heading 2||Table heading 3|
|Row 1, Cell 1||Row 1, Cell 2||Row 1, Cell 3|
|Row 2, Cell 1||Row 2, Cell 2||Row 2, Cell 3|
Feel free to add extra data to the array once your table generation works.
Your HTML output is still required to be valid HTML5. Validation will be done through http://validator.w3.org.Homework Submission
As detailed on the homework submission page, this homework must be on the class web server in a folder titled homework7 for it to be graded.