PHP and MySQL

PHP Reference with functions:

http://w3schools.com/php/default.asp

First PHP Lesson:

See it in action:
http://andrewarpasi.com/php/Untitled-1.php

<?php
//This code prints hello world on the screen
echo "<br>";
echo "hello world";
echo "<br>";
$avar="Printthis!";
$anum="6";
echo $avar . " " . $anum;
echo "<br>";
echo strlen("Hello world!");
echo strpos("Hello world!","world");
?>

This code uses comments (//) string variables, integer variables and the echo statement also uses strpos() and strlen() to find the string position and length.

PHP Operators (from http://www.w3schools.com/php/php_operators.asp)
Operator
Description
Example
Result
+
Addition
x=2
x+2
4
-
Subtraction
x=2
5-x
3
*
Multiplication
x=4
x*5
20
/
Division
15/5
5/2
3
2.5
%
Modulus (division remainder)
5%2
10%8
10%2
1
2
0
++
Increment
x=5
x++
x=6
--
Decrement
x=5
x--
x=4
Lesson 2 uses if/else and operators
See it in action
http://andrewarpasi.com/php/Untitled-2.php
<?php
echo "php lesson 2";
echo "<br>";
//operators
$x = 4;
$y = 5;
echo $x * $y;
//if else
if($x > $y)
echo "x is larger than y";
else
echo "x is not larger than y";
 
?>

PHP Switch Statements
See it in action:
http://andrewarpasi.com/php/switch.php


<?php
switch ($x)
{
case 1:
 echo "Number 1";
 break;
case 2:
 echo "Number 2";
 break;
case 3:
 echo "Number 3";
 break;
default:
 echo "No number between 1 and 3";
}
?>
 
 
PHP Arrays
See it in action:
http://andrewarpasi.com/php/Untitled-3.php

In PHP and many other programming languages, you use 0 to get the first item, not 1. In this example, 0 gets "ThinkeringStudio", 1 gets "PHP" and 2 gets "Dreamweaver".
<?php
$mylist=array("ThinkeringStudio","PHP","Dreamweaver");
echo $mylist[1];
echo "<br>";
echo $mylist[0];
?>
Loops
While loop:
http://andrewarpasi.com/php/while.php
<?php
$count=1;
while($count<=7)
 {
 echo "The number is " . $count . "<br />";
 $count++;
 }
?>
 
Do while:
http://andrewarpasi.com/php/dowhile.php
<?php
//do while statement
$i=1;
do
 {
 $i++;
 echo "The number is " . $i . "<br />";
 }
while ($i<=5);
?>

For loops:
Example:
http://andrewarpasi.com/php/forloops.php
<?php
for ($i=1; $i<=5; $i++)
 {
 echo "The number is " . $i . "<br />";
 }
?>
Functions:
In a function, the code won't be executed unless you call the code.
Example:
http://andrewarpasi.com/php/functions.php

<?php
//Functions Demonstration
function TheBestSchool()
{
echo "BCS";
}
 
echo "A great place to be: ";
TheBestSchool();
?>
PHP Forms
Example:
http://andrewarpasi.com/php/form.php
You can use this to collect user data. It is only stored temporarily. Later we will get into MySQL databases and using them to store data on the server.
<input type="text" name="tbname" />

This is what you use to create a textbox, and tbname (you can replace with whatever you want) is what you would use $_POST to display the data.
frmdata.php:
<html>
<body>
 
Welcome <?php echo $_POST["fname"]; ?>!<br />
Your favorite food is: <?php echo $_POST["food"]; ?>
 
</body>
</html>
form.php:
<form action="frmdata.php" method="post">
Name: <input type="text" name="fname" />
Favorite Food: <input type="text" name="food" />
<input type="submit" />
</form>


More coming soon