CSC220 Lab 3 2010

From dftwiki3
Revision as of 19:53, 19 September 2010 by Thiebaut (talk | contribs) (Preamble)
Jump to: navigation, search

--D. Thiebaut 23:42, 19 September 2010 (UTC)


This lab deals with Php programming. You will need to use your 220a-xx account and create your Php files/pages in the public_html directory.

To access the page you create, simply point your browser to the URL http://cs.smith.edu/~220a-xx/yourfile.php where you will replace yourfile by the actual name of the file. Similarly, replace xx by your two-letter Id.








Preamble

  • By default, your browser will try to be clever and not reload a page twice if you ask it to reload it. Instead it keeps a copy of the page it just fetched in a cache, and reloads it from cache instead of actually getting it back from the server.
  • Since you are writing Php code, you will need to modify your code as you go along, and will want to see the result by reloading your page in your browser. To prevent the browser to use the cache and force it to go back to the server for the page, make your Php page start as follows:
<html>
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<PRAGMA NO-CACHE>
<head>
<title>Php variables</title>
</head>
<body>
...

First Problem

  • Write a php page that declares 2 variables $a, and $b, set both of them to some values of your choice, and displays their contents, sum, and difference.
  • Your page should display something like this:
$a = 5
$b = 10
$a + $b = 5 + 10 =  15
$a - $b = 5 - 10 =  -5
  • Make sure you create your page in your ~220a-xx/public_html directory, and remember to chmod a+r your Php files!

Second Problem

  • Write a Php page that uses a for loop and that displays all the numbers from 1 to 10, as follows:
1
2
3
4
5
6
7
8
9
10

Third Problem

  • Same as Problem 2, but add a test in your loop so that the output becomes as shown below:
1 odd
2 even
3 odd
4 even
5 odd
6 even
7 odd
8 even
9 odd
10 even


Fourth Problem

  • Same as Problem 3, but this time the 10 lines are output in an html table.
  • The code for the table should look something like this:
       <table>
       <tr><td>1 odd</td></tr>
       <tr><td>2 odd</td></tr>
       <tr><td>3 odd</td></tr>
       <tr><td>4 odd</td></tr>
       <tr><td>5 odd</td></tr>
       <tr><td>6 odd</td></tr>
       <tr><td>7 odd</td></tr>
       <tr><td>8 odd</td></tr>
       <tr><td>9 odd</td></tr>
       <tr><td>10 odd</td></tr>
       </table>










[[Category:CSC220]