Sunday, February 19, 2012

Individual Tutorial & Reflection #1 - PHP

For my first attempt at learning PHP, I browsed through a few different sites that offered tutorials.  I found a site called Learn PHP By Examples; it seemed to be a very user friendly site, so I decided to go for it.

Introduction to PHP...

On the left menu of the site there is a PHP Guide, which I began to follow.  The first thing I did was read the Introduction to PHP. A lot of this was review because it was information I had learned for the Technology Research Assignment.

PHP Installation... 
Next, I followed the instructions for PHP Installation.  I thought it would be a difficult process for some reason, but it was actually super easy to download and install WAMP5, which all I had to do to get PHP on my computer. Now that it's on there, there will be a little WAMP5 icon that I can click on any time from my taskbar, as you can see from the screenshot below. "WAMP5 is an open source application which comes with with PHP5, Apache web server, MySQL database and phpMyAdmin (mysql database administration program)." It only took me about 10 minutes to get it up and running.

The next step was to "Start All Services," so I clicked as shown here...

Then, I typed in http://localhost in my web browser, and it took me to the WAMP homepage:

PHP Syntax...

The next lesson, PHP Syntax, explains how HTML and PHP "work together."

"When writting php code, you enclose your PHP code in special php tags. This tells the browser that we're working with PHP."
//your php code goes here
 The next part of the lesson was to create my first PHP page!  (I actually got really excited when I got to this point...) I followed the steps (open notepad, copy the code from the tutorial, save the file in a wamp folder...)

....and... Voila! My first PHP page! "hello there!"

I went on to make the "hello world" bold and green by manipulating the code as directed by the tutorial.  I also learned how to write today's date.  I honestly thought it would be hard to use PHP - but so far, it is not too bad!  As simple as it was, I was really proud of myself to have made my very first PHP pages.

PHP Variables...

In PHP, variables are used to "store values such as strings (i.e words, phrases, etc.?) or integers. In PHP, variables are defined with a dollar sign, a variable name, and a value.
$variable_name = value;

 The tutorial gives an example of a code including variables to try, which I did...

This section also gave examples of a PHP variable with a string value, a PHP variable with an integer value, and a PHP variable with a float or decimal value.

PHP Variables FAQ and Examples...

In this section, I came across a word I had never seen before: concatenate. To concatenate means to "link together or unite a series or chain."  This is apparently an immportant concept when it comes to computer programming languages, and that would make sense!

PHP Strings...

The next section of the tutorial gave an in-depth explanation of strings how they can be stored, which is by storing the string value in a variable name ($str) and "use echo to output its value." (Echo is a special statement in php for outputing data to the browser.)

The section also discussed using PHP strings in single quotes and double quotes.  Single quotes  are used when outputting HTML code.  Double quotes are used for special characters in a string. 

PHP Operators...

The next part of the tutorial provided information on different kinds of operators (arithmetic, comparison, and logic) and how they are coded in PHP.

PHP If Else Statement...

I tried another example in this section, which used conditional, or "if else," statements. Using conditional statements is useful when writing logic is required or decisions have to be made by the code.

Example 1. If Else Statement in PHP

 Example 2. The Else If Statement

 PHP Switch Statement...

This was the last section I decided to look at for the week.  The next section will discuss arrays, which seems to be on an other level, so I will stop here and marinate...

Switch statements are like if-else conditional statements in that "a block of code will be executed if a condition is true." They can also be used to "evaluate different cases of a given scenario" by taking a "single variable as input and then checks it against all cases in the switch statement." (Side note: This reminds me about how Jay is envisioning the interactive database to work for his project...I wonder if something like this is what the PHP would be user for.)

No comments:

Post a Comment