Week 5, S2, 2017-PHP

1. Basic PHP Syntax
2. MySQL DB Connection 3. Using PHP and MySQL 4. Using PHP and jQuery
On completion of this tutorial you should have:
 Completed some PHP pages which make use of PHP functions, transferred them to the Triton server and displayed them via a browser
 Connected to the MySQL database, created a table and added some data to that table
 Displayed a MySQL table via a PHP script
Tutorial Tasks
Task 1 – Basic PHP
1. Create a new PHP using any text editor you choose. Using something like Visual Studio or Dreamweaver would probably be advantageous due to their “colour-coding” which helps easily differentiate HTML from PHP syntax. At the least, you should choose an editor that includes line numbers, as this will aid in tracking down errors in your code.
2. Using the lecture notes as a guide, create a PHP file that displays the current date in dd/mm/yyyy format. Make sure that you save the file with a .php extension
3. Transfer the file to your directory on Triton using either FTP or GIT. The IP address of Triton is or you can use triton.infotech.monash.edu.au as the host name.
4. View the file that you have created via a browser. The URL will be http://triton.infotech.monash.edu.au/11111111/t1.php where 11111111 is your student id and t1.php is the name of the file that you created.
5. Ensure that you see today’s date in dd/mm/yyyy format.
It’s important that you master the task of transferring files to Triton and viewing them via a browser, as this is how your assignments will be submitted.
Task 2 – PHP rand() function
1. Create a new PHP file using any text editor you choose. Using the lecture notes as a guide, create an array called $numbers and assign numeric values to the first 6 elements (you can just make up numbers).
 Display the contents of the array sorted numerically in ascending order
 Display the contents of the array sorted numerically in descending order
 Display the average, minimum and maximum values of the array contents
HINT: Try looking in the PHP Manual for the array_sum() function
Task 3 – PHP for loop
1. Create a new PHP file using any text editor you choose. You need to create a function that will create a HTML table. The function will take 2 arguments and will use a for loop to create a table which contains the number rows as specified by argument 1 and the numbers of columns as specified by argument 2. Each cell within the table will display the row and column number.
The page should look something like this.
Task 4 – MySQL DB Connection
1. You’ll need some way of connecting to the MySQL DB Server. You can use PHPMyAdmin on Triton at http://triton.infotech.monash.edu.au/phpmyadmin/index.php or download a database client of your choice.
2. Your username is s99999999 (where 99999999 is your student id) and the password is monash00. Your database name is s99999999 (where 99999999 is your student id). If you connect from your own laptop or home PC, the IP address of the database server is
3. After a successful logon, you should see something like this. You will only be able to see your own database.

4. If you wish to change your password, select the SQL tab and enter the command
set PASSWORD=PASSWORD(‘newpass’);
Where newpass is your new password.
5. You can either execute sql commands in this tab to create tables and enter data or use the PhpMyAdmin GUI to do so.
6. Create a Product table (for your assignment).
7. Add some data to this table.
8. Create a PHP file that displays this data, transfer the file to Triton and display it via a browser. Ensure that you see the data as expected.
Task 5 – jQuery Alternating Row Colour
1. Using the lecture notes as a guide, add a link to the jQuery library in your PHP page. Then, add the required CSS class definitions.
2. Create a JS file with a function to alternate row colours.
3. Add a link to the JS file in your PHP page and ensure that your table has the required id attribute.
4. Transfer this file to Triton and ensure that it displays correctly
It should look something like this
Task 6 – Assignment tables
1. Create the rest of the tables required for your assignment. Don’t forget that you will need to create the Foreign Key relationships.


电子邮件地址不会被公开。 必填项已用*标注