Thursday, August 23, 2018

Videos for Week 3 Chapters 3-4

Getting started with the MAMP/WAMP server

https://www.youtube.com/watch?v=Qy2F7qpy46k


Textbook Chapter 1: Client-Server Interactions

https://www.youtube.com/watch?v=2hIOOP0ztEo


Chapter 3 Part 1

https://www.youtube.com/watch?v=Xtw3cXM93Xk

Code comments, PHP source code vs. HTML source code vs. HTML visual, Arithmetic operators, increment, automatic conversions, arrays, print_r, array indexing, out of bounds, variable naming rules.


<!--
Susan S. Student
9 Sept. 2017
PHP 86 at Mission
-->

<?php

  /* Susan S. Student
     9 Sept. 2017
     PHP class CIS 086 at Mission College
   */

  // This is a comment
  // echo "X equals $x";

  $x = 50;
  echo $x;
  $x += 14;
  echo "<br />\n";
  echo $x;
  $x = $x + 14;
  echo "<br />\n";
  echo $x;
  $x++;
  echo "<br />\n";
  echo $x;
  $x--;
  echo "<br />\n";
  echo $x;

  $x = "Fred Smith";
  echo "<br />\n";
  echo $x;

  $x = 3.14;
  echo "<br />\n";
  echo $x;

  $x = array ("Alice", "Bob", "Chris", "Dean", "Eliza");
  echo "<br />\n";
  print_r ($x);

  $x = [ "Red", "Orange", "Yellow", "Green", "Blue", "Purple" ];
  echo "<br />\n";
  print_r ($x);

  echo "<br />\n";
  echo $x[3];

  echo "<br />\n";
  echo $x[5];

  echo "<br />\n";
  echo $x[2];

  echo "<br />\n";
  echo $x[4];

  echo "<br />\n";
  echo $x[0];

  echo "<br />\n";
  echo $x[1];
  echo "<br />\n";

  $_foo = "bar";
  echo $_foo;
  echo "<br />\n";

  /*$1foo = "no bar";
  echo $1foo;
  echo "<br />\n";*/

  /*foo = "wassap";
  echo foo;
  echo "<br />\n";*/

  echo $_FOO;
  echo "<br />\n";
?>

Chapter 3 Part 2

https://www.youtube.com/watch?v=3PkEEjhzpAI

Arithmetic, integers, floating point, modulo operator, comparison operators, logical operators (and, or)


<?php

  $a = 50; 
  $b = 6;
  $d = 14;
  $e = 14;
  
  // arithmetic operators
  $c = $a + $b;
  echo "$c<br />\n";

  $c = $a - $b;
  echo "$c<br />\n";

  $c = $a * $b;
  echo "$c<br />\n";

  $c = $a / $b;
  echo "$c<br />\n";

  $c = $a % $b;
  echo "$c<br />\n";

  // arithmetic assignment operators
  $c += 17;
  echo "$c<br />\n";

  $c -= 37;
  echo "$c<br />\n";

  $c *= -2;
  echo "$c<br />\n";

  $c /= 3;  // $c = $c / 3;
  echo "$c<br />\n";

  // comparison operators
  if ($a == $b)
    echo "Equal<br />\n";
  else
    echo "Not Equal<br />\n";

  if ($a != $b)
    echo "Not Equal<br />\n";
  else
    echo "Not Not Equal<br />\n";

  if ($a < $b) 
      echo "A is less than B<br />\n";
  else
      echo "A is NOT less than B<br />\n";

  if ($a > $b) 
      echo "A is greater than B<br />\n";
  else
      echo "A is NOT greater than B<br />\n";

  // logical operators: AND
  if ($a < $b && $b < $d)
    echo "The numbers are in order<br />\n";
  else
    echo "The numbers are NOT in order<br />\n";

  // logical operators: AND
  if ($a > $b && $a > $d) 
    echo "A is the bigger number<br />\n";
  else
    echo "A is NOT the bigger number<br />\n";

  // logical operators: OR
  if ($b == $d || $d == $e)
    echo "Two of the numbers are the same<br />\n";
  else
    echo "No two of the numbers are the same<br />\n";
?>

Chapter 3 Part 3

https://www.youtube.com/watch?v=F4WPxwkmaWY

Strings, concatenation, multi-line statements, automatic conversions, constants, define, substr (substring)


<?php

  $msgs = 417;
  $s = "You have " . $msgs . " messages.<br />\n";
  echo $s;
  $t = "You have $msgs messages.<br />\n";
  echo $t;

  $t .= "Please listen to your messages.<br />\n";
  echo $t;

  // $t .= 'The machine is almost out of space.<br />\n';
  $t .= 'Ray\'s auto parts called.<br />';
  echo $t;

  $p = "She wrote upon it, \"Return to sender.\"";
  echo $p;
  echo "<br />\n";

  $p = "She wrote upon it, 'Return to sender.'";
  echo $p;
  echo "<br />\n";

  $p = 'She wrote upon it, "Return to sender."';
  echo $p;
  echo "<br />\n";

  $lincoln = "Fourscore and seven years ago our forefathers " .
      "brought forth on this continent a new nation<br />\n";

  echo $lincoln;

  $number = 12345 * 67890;
  echo $number . "<br />\n";
  echo substr ($number, 3, 3);
  echo "<br />\n";
  echo substr (1234, 1, 2);
  echo "<br />\n";
  echo substr (1234, 1, 2) * 2;
  echo "<br />\n";

  define ("PI", 3.1415926);
  $radius = 6;
  echo $radius * $radius * PI;
  echo "<br />\n";

  // constants
  define ("STUDENT_PRICE", 9.50);
  define ("SENIOR_PRICE", 8.00);
  define ("CHILD_PRICE", 6.00);

  $student_price = 9.50; // NOT a constant because it can be changed later

  $student_price = 10.50; // ok to change a variable value

  // STUDENT_PRICE = 10.50;
  define ("STUDENT_PRICE", 10.50); // will not happen
  echo STUDENT_PRICE;
?>


Chapter 3 Part 4

https://www.youtube.com/watch?v=kYMS30XNmZE

Functions, return values, scope, local scope, global scope, superglobals ($_SERVER)



<?php

function printline ($s) {
    echo $s . "<br />\n";
}

printline (3+4);
$x = 3;
$m = 5;
$b = 7;
$y = $m * $x + $b;
printline ($y);
printline ("Now is the time for all good men ...");

function calculate_y ($x, $m, $b) {
    return ($m * $x + $b);
}

printline (calculate_y ($x, $m, $b));

$y = calculate_y ($x, $m, $b);
printline ($y);

printline (calculate_y( 5, 2, 9));
printline (calculate_y( 9, 42, 17));

// global variable
$rsquared = 16;

function calculate_area ($r) {
    $rsquared = $r * $r; // local variable
    return 3.1415926 * $rsquared;
}

$a = calculate_area (5);
printline ($a);

printline ($rsquared);

function calculate_volume ($r) {
    $rsquared = $r * $r; // local variable
    $rcubed = $rsquared * $r;
    return $rcubed * 3.1415926 * 4 / 3;
}

printline (calculate_volume (5));

// $i, $j, $a, $b, $x, $y

print_r ($_SERVER);
print_r ($_GET);
print_r ($_POST);
print_r ($_COOKIE);

echo `ls -al`;
echo `du -sk *`;
echo `ls -al ../..`;
?>

Chapter 4 Part 1

https://www.youtube.com/watch?v=X4E7dbsXzKo

Boolean logic, and, or, not, literals, variables, quotation marks in strings, unary operator, binary operator, operator precedence, parentheses, operator associativity.


<?php

// literals
$name = "Mark"; // Mark is a literal; $name is a variable
$age = 39; // lying
$students = array ("George", "Wilma", "Ivan", "Rose");
$stuff = array ("Tomatoes", 7, "Milk", 3.14);

// $name = Mark Brautigam; // no good, string must be in quotation marks
echo $name; // printing a variable
echo $age;

echo "Mary"; // print a literal

print_r ($students);
print_r ($stuff);
print_r ($students + $stuff);

// unary operator has one operand
// = is a binary operator, has two operands
$a = - $b;

// precedence
$a = 3 + 5 * 7; // multiply first
                // addition 2nd
                // = assignment LAST

$a = 3 * 5 + 7; // multiply, then add, then assign

// change OR CLARIFY precedence with parentheses
$a = (3 + 5) * 7; // parentheses first, then +, then * , then =

// example

total = 1 + 2 * 3 / 4 + 5 * 6 - 7 / 8 + 9
total = 1 + (2 * 3) / 4 + 5 * 6 - 7 / 8 + 9
total = 1 + (6 / 4) + (5 * 6) - (7 / 8) + 9
total = (1 + 1.5) + 30 - 0.875 + 9
total = 2.5 + 30 - 0.875 + 9
total = 32.5 - 0.875 + 9
total = 31.625 + 9
total = 40.625

// [1] multiplication and division and modulo, left to right, no distinction
// [2] addition and subtraction, left to right, no distinction
// [3] assignment, right to left
?>




Videos for homework 3

These videos will give you an idea what I am looking for in Homework 3 Exercises 3, 4, and 5.

Homework 3 images and research
https://youtu.be/GXrM5IU4pdI

<!DOCTYPE html>
<html>
<head>
  <!--
  Mark Brautigam
  CIS 86: PHP and MySQL
  2017 Aug 30
  -->
  <meta charset='utf-8' />
  <title>My 12 Images</title>
  <style type='text/css'>
  /* styles go here */
      body { text-align: center; }
      img { width: 144px; box-shadow: 2px 2px 4px gray; 
          margin: 8px; 
      }

  </style>
</head>

<body>
  <h1>My 12 Images</h1>
  <!-- page content will go here -->
    
    <img src='acrobat.png' alt='Acrobat' />
    <img src='audition.png' alt='Audition' />
    <img src='bridge.png' alt='Bridge' />
    <img src='capture.png' alt='Capture' />
    <br />
    <img src='cloud.jpeg' alt='Creative Cloud' />
    <img src='comet-icon.png' alt='Comet Project' />
    <img src='comp.png' alt='Comp CC' />
    <img src='illustrator.png' alt='Illustrator' />
    <br />
    <img src='indesign.png' alt='InDesign' />
    <img src='lightroom.png' alt='Lightroom' />
    <img src='photoshop.png' alt='Photoshop' />
    <img src='spark-post.jpg' alt='Spark Post' />
    
</body>
</html>



Homework 3 buttons
https://youtu.be/VYUYePuatcs

<style type='text/css'>
    a.button {
        display: block;
        padding: 0.75em 1em;
        background-color: #08c;
        color: white;
        text-decoration: none; 
        margin: 0.5em 0; 
        font-family: sans-serif;
        width: 160px;
        text-align: center;
        border-radius: 8px;
        background: linear-gradient(#08c,#07b);
    }
</style>

<a class='button' href='home.php'>Home Page</a>
<a class='button' href='control.php.'>Control Structures</a>
<a class='button' href='strings.php'>String Functions</a>
<a class='button' href='webforms.php'>Web Forms</a>
<a class='button' href='state.php'>State Information</a>

Videos to get you started

Install WAMP on Windows in 16 minutes or less

https://www.youtube.com/watch?v=ZdsQV400d2w



Install MAMP on Mac OS X in 12 minutes

https://www.youtube.com/watch?v=kuBxgaaIEzY



HTML Review Part 1

https://www.youtube.com/watch?v=QX2khy4I-JM



HTML Review Part 2

https://www.youtube.com/watch?v=_xIosfaiwzc



HTML Live Action Demo

https://www.youtube.com/watch?v=yBka1tSaOzI



HTML Best Practices

https://www.youtube.com/watch?v=OxrRgR9NePU



Uploading your web page to the Mission College PHP server

https://www.youtube.com/watch?v=FGy2UBoTS68



Basic HTML

Here is a template for the minimal complete HTML page. If your page doesn't have all these elements, you should edit your page to include all of them. When you start a new page, you can copy and paste this code to get started.

<!DOCTYPE html>
<html>
<head>
  <!--
  Mark Brautigam
  CIS 86: PHP and MySQL
  2017 Aug 30
  -->
  <meta charset='utf-8' />
  <title>My Web Page</title>
  <style type='text/css'>
  /* styles go here */

  </style>
</head>

<body>
  <h1>My Web Page</h1>
  <!-- page content will go here -->

</body>
</html>

Here is the code for a bullet list:
<ul>
  <li>Mission College
  <li>Ohlone College
  <li>Foothill College
  <li>Cabrillo College
</ul>

Here is the code for a table:
  <table>
    <tr>
      <th>Key</th>
      <th>Command</th>
    </tr>
    <tr>
      <td>Cmd-Space</td>
      <td>Spotlight</td>
    </tr>
    <tr>
      <td>Cmd-S</td>
      <td>Save</td>
    </tr>
  </table>

Here is an excellent tutorial on HTML tables (thank you to the student who linked this to your page):

http://www.w3schools.com/html/html_tables.asp


First!

This will be the web site for CIS 086: Web Development with PHP and MySQL, at Mission College in Santa Clara, California.

I will post video lectures online here (and possibly in Canvas also). We will have lab time together on Saturday mornings from 9:00 am until 12:10 pm. Our first lab session will be on August 25, 2017. Lab attendance is mandatory and we will take attendance each Saturday.

The textbook will be Learning PHP, MySQL, and JavaScript, with jQuery, CSS, and HTML5, by Robin Nixon. You can get the textbook in the Mission College Bookstore or you can order it from Amazon. This is a new textbook. We are the first class who will use this textbook at Mission College. It includes lots of material that we won't cover in this class, but you will find it useful if you take other classes like JavaScript or Web Design.