On the course
blog post a comment to my post asking for two examples of
well-designed web pages. Explain briefly what you liked about these
pages. Feel free to comment on other students' suggestions.
Recall that your login name for wordpress is your last name, and your
password is what it used to be on rynite before you reset it. You can
chose a nickname for your post, just make sure that it's clear to
others in the class who you are.
You are given the following file with HTML and PHP code:
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Author: Elena Machkasova elenam@morris.umn.edu
Last modified: 2/7/06
-->
<?php
$color1 = "orange";
$color2 = "darkred";
?>
<html>
<head>
<title>
Alternating colors example
</title>
</head>
<body>
<ol>
<li>List element</li>
<li>Another list element</li>
<li>And another one</li>
<li>Finally, the last one</li>
</ol>
</body>
</html>
Your task is to write a PHP program that displays results of voting for two candidates as color bars of three different colors. The names of the candidates and the number of votes for each candidate are set in variables in the beginning of the program.
The code also shows a sample of displaying a color bar followed by the name of a candidate. The width of the color bar, the name of the candidate, and the votes are all fixed in the example, you need to change this so that all of them depend on the variables (for instance, if the number of votes changes from 15 to 20 in $votes1, the width of the color bar is automatically set to 100px). You also need to add another table to display the votes for the other person.
Format the page any way you like. Add a header to explain what the
page is about.
Note that padding property for <td> in the embedded style
sheet. Feel free to change it if you prefer a different formatting.
Make sure to check your page for several different names and numbers of votes.
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Author: Elena Machkasova elenam@morris.umn.edu
Last modified: 2/9/06
-->
<?php
$name1 = "Bart Simpson";
$name2 = "Lisa Simpson";
$votes1 = 15;
$votes2 = 12;
?>
<html>
<head>
<title>
Voting results
</title>
<style type="text/css">
td {padding: 3px}
</style>
</head>
<body>
<table>
<tr>
<td style="background: blue; height: 20px; width: 75px;" />
<td>
Bart Simpson 15
</td>
</tr>
</table>
</body>
</html>
In the voting program in the previous question print out the name of the winner. If it's a tie, print out both names and a message saying that they got equal number of votes.
Recall the program hours.php that prints a greeting based on the time of the day (the lecture examples are posted here). Change the program so that it prints out the time in a standard am/pm format. For instance, if the input is 13, the program should print 1pm. If the input is less than 0 or greater than 23, the program should print "Invalid time".
You are given a PHP file that displays a table:
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Formatting a table in PHP
Author: Elena Machkasova elenam@morris.umn.edu
Last modified: 2/15/06
-->
<?php
$row = $_GET["input1"];
$column = $_GET["input2"];
$color = "lightgreen";
$r = 0;
$c = 0;
?>
<html>
<head>
<title>
Setting a table background to a specific color.
</title>
</head>
<body>
<h3>
<?php print "Column $column in row $row of this table must be $color"; ?>
</h3>
<table border="2">
<tr <? $r++ ?> >
<td <? $c++ ?> >
<? print "row $r column $c\n"; ?>
</td>
<td <? $c++ ?> >
<? print "row $r column $c\n"; ?>
</td>
<td <? $c++ ?> >
<? print "row $r column $c\n"; ?>
</td>
</tr>
<tr>
<td>
TEXT
</td>
<td>
TEXT
</td>
<td>
TEXT
</td>
</tr>
<tr>
<td>
TEXT
</td>
<td>
TEXT
</td>
<td>
TEXT
</td>
</tr>
</table>
</body>
</html>
This page is a part of CSci 1101 course web site.