task:
b. Create a php script to [See Week 3 worksheet]
- receive the chosen option from the select box & textbox in the html file & check it is within range and is a number (using the is_numeric( ) function)
- Assign 7 employee records (Employee Number, Employee Name, Age, Department Name) into a 2 dimensional sequential array (using employee numbers 1 to 7) and your own made up values for the other record details – remember that text values are enclosed within inverted commas whereas numeric values are not:
- See PHP worksheet 3 for how a 2D array is created in a program
- If the chosen select option is to print the whole table
o – then print all 7 records in an html table with a header row
• You will need a for loop to print a record
• You will need to manipulate array values
(You should use a variable for the row number to
generalise row printing a row using the for loop)
- If the chosen option is to print a selected record, use the record number from the textbox to
o Print that particular record including the header details row
• E.g. for employee number 1 by transposing it to the array row index number
• This row number should be generalised using a variable for the row index number
• Sample record
Employee Number Employee Name Age Department Name
1 J Smith 55 Sales
this what i have so far:
Code: Select all
<?php
$output = "";
$total = 0;
for($i = 1; $i <= 7; $i++) {
$people = array(array(21, "John"), array(25, "Bill"), array(23, "Anna"),
array(29, "Aine"), array(19, "Pat"), array(30 , "Leanne") );
print "<table border=1>";
print "<tr><th>Age</th><th>Name</th></tr>";
for($x=0;$x<6;$x=$x+1) {
print "<tr><td>" . $people[$x][0] . "</td>";
print "<td>" . $people[$x][1] . "</td></tr>";
}
?>