Write the complete PHP page that will generate the outcome shown below. The data
ID: 3582955 • Letter: W
Question
Write the complete PHP page that will generate the outcome shown below. The data comes from a text file named players.txt, whose content is shown below on the right. You will need to generate an html table and you will have to calculate total points for each player (goals+assists) as well as the sum.
File Edit View Favorites Tools Help Top scorers in the NHL Player Name Team Goals Assists Total Points M St. Louis Tampa Bay 38 56 94 I. Kovalchuk Atlanta 41 46 87 J. Sakic Colorado 33 54 87 M Naslund Vancouver 35 49 84 M Hossa Ottawa 36 46 82 Done Internet players.txt Notepad File Edit Format View Help M. St., Louis, 38, 56, Tampa Bay I. Kovalchuk,41,46, Atlanta J. Sakic, 33, 54, Colorado M.,Naslund, 35, 49,Vancouver M., Hossa, 36,46, OttawaExplanation / Answer
Note: the file shoud be in the same folder as code.
Here is the full code:
<?php
$data = array(); //making a double dimension array to parse and store data
foreach(file('file1.txt') as $line) { //storing data in array, from file
$line_data = explode(",", $line); //splitting values by comma(,) from file
array_push($data, $line_data); //each line is an array with comma separated values
}
?>
<html>
<head>
<title>Chegg</title>
</head>
<body>
<h1>Top Scorers in the NHL</h1>
<table border="1">
<tr>
<th>Player Name</th>
<th>Team</th>
<th>Goals</th>
<th>Assists</th>
<th>Total Points</th>
</tr>
<?php
foreach($data as $row_data) //making the table for display in html
{
?>
<tr>
<td><?php echo $row_data[0].' '.$row_data[1] ?></td>
<td><?php echo $row_data[4] ?></td>
<td><?php echo $row_data[2] ?></td>
<td><?php echo $row_data[3] ?></td>
<td><?php echo ($row_data[2]+$row_data[3]) ?></td> <!-- addition to get total scores -->
</tr>
<?php
}
?>
</table>
</body>
</html>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.