Put your work for this lab into a new folder public_html\cs1109\lab17
.
Take a copy of to_binary.html
;
do not modify it.
It allows a user to enter a non-negative integer. You can assume that your
user is 100% cooperative: s/he never enters any incorrect characters.
You must write to_binary.php
, which computes and outputs a string
that represents the binary that corresponds to the integer that the user
has entered.
For example, if the user enters "37", your program outputs the string
"100101"
Reminder: you covered the algorithm in CS1101; it involves repeated division by 2, noting the remainders.
You do not need and must not use any
built-in functions; in particular, use of decbin
is not allowed.
This exercise allows you to practice using databases.
First you must create a database.
Save a copy of the following file in your lab17
folder; do not edit it: eurovision.sql.
As you did in Induction, use ssh
(or PuTTY
) to login to
cs1
.
On cs1
, type the following:
mysql -u userid -p
replacing userid with your database user id (the one you used in CS1106).
You will be asked for a password. Again, use the one you used in CS1106.
When you are logged into the database, type the following:
use dbname;
replacing dbname with your database name (the one you used in CS1106). Next type:
source ~/public_html/cs1109/lab17/eurovision.sql;
(assuming that this is where you stored the eurovision.sql file).
If all of that worked OK, then you now have one database
table called winners
, which has
the following columns: year
, country
, song
,
performer
& points
.
If you want to check, then type:
select * from winners;
You should see a table of Eurovision winning songs.
You can now close down ssh/PuTTY.
Take a copy of eurovision.html
;
do not modify it.
It allows a user to enter a country and/or a number of points.
You must write eurovision.php
, which will work as follows:
In all cases, your script should output the relevant winners in an HTML table.
You can use
output_functions.phps
and validation_functions.phps if you wish.
If you do use either of these files, please store them (as
output_functions.php
and
validation_functions.php
in your lab17
folder, and not somewhere else.
Here are some optional activities:
get_optional_string
and
get_optional_int
, rather than
get_required_string
and
get_required_int
.
If the user doesn't supply a value, my functions will return
NULL
.
eurovision.css
to prettify the form and to
prettify the results table. E.g. how about using
zebra-striping for the table?
SELECT DISTINCT country FROM winners;
).
I haven't shown you how to create HTML menus. So this optional
activity comes with the additional challenge of finding out
how to do this from textbooks or the Web.
If you tackle any of the optional activities, make sure you don't break your program, resulting in a grade of zero.
Deadline: 1pm, Tuesday 5th March.
If you have named your files and folders correctly, your work will be collected automatically at that time by my software.
The final lab sheet, lab 18, will be a 'project' that will last until the end of term.
In time for next week, think of a scenario where you would want to maintain a database and to update and query the database from your web browser. For example, a club or society may wish to keep membership records; a social network will want to store its members, their connections, and so on; a bookshop may wish to keep track of its stock; a busy house-husband may wish to keep a diary of dental appointments, birthdays, and Pilates lessons; a quiz program would store questions, answers, and the scores of its users in a database;...
Examples from previous students include: database-driven quiz programs, CD/DVD/gaming shops, libraries, social networking sites, bulletin boards,...
Make sure your chosen scenario is ambitious enough to warrant a 'project' that will last until the end of term. (E.g. a database with just one table, a form for insertion and a form for retrieval is almost certainly not challenging enough.)
You should check your chosen scenario with me. You can do this at any point, no later than the start of next week's lab. Once I have agreed it, you can start designing your database, your forms and your scripts.
Bear in mind that there will be lectures on PHP for cookies, sessions (including shopping carts), and user authentication (i.e. user registration and user login).
Bear in mind that access to the labs might be reduced in the penultimate week of term due to the public holiday on the Monday and to Year 4 students holding their Project Open Day.
(There's no challenge exercise this week. Instead, you'll be eager to begin lab 18.)