Programming For Designers V3
-
Upload
sqoo -
Category
Technology
-
view
1.370 -
download
0
Transcript of Programming For Designers V3
![Page 1: Programming For Designers V3](https://reader036.fdocuments.net/reader036/viewer/2022062703/55555f7fb4c9052b208b5416/html5/thumbnails/1.jpg)
Overcoming code fear
An introduction to programming for designers
![Page 2: Programming For Designers V3](https://reader036.fdocuments.net/reader036/viewer/2022062703/55555f7fb4c9052b208b5416/html5/thumbnails/2.jpg)
Unintelligible - Yuk
^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$
![Page 3: Programming For Designers V3](https://reader036.fdocuments.net/reader036/viewer/2022062703/55555f7fb4c9052b208b5416/html5/thumbnails/3.jpg)
But not all code is squiggles!
SUBTRACT Tax FROM GrossPay GIVING NetPay
![Page 4: Programming For Designers V3](https://reader036.fdocuments.net/reader036/viewer/2022062703/55555f7fb4c9052b208b5416/html5/thumbnails/4.jpg)
So what is a script?
• A script for a play defines a cast and gives them instruction to produce the desired result, a play.
• A script for a computer could be said to be the same. It defines the resources and how they are used in a prescriptive manner to achieve a desired result. The words script and program can be used interchangeably.
![Page 5: Programming For Designers V3](https://reader036.fdocuments.net/reader036/viewer/2022062703/55555f7fb4c9052b208b5416/html5/thumbnails/5.jpg)
Languages
• BASIC, C++, Java, JavaScript, Lisp, SQL, PHP, Perl, Python, Ruby
• Why is HTML not considered a programming language?
• Why is ASP not on this list?
• Learn one language and you have learned a lot about many others.
![Page 6: Programming For Designers V3](https://reader036.fdocuments.net/reader036/viewer/2022062703/55555f7fb4c9052b208b5416/html5/thumbnails/6.jpg)
A standard HTTP request
Request hello.HTML
<h1>Hello</h1>
goodbye.HTML
<h1>Hello</h1>
hello.HTML
Browser Server
![Page 7: Programming For Designers V3](https://reader036.fdocuments.net/reader036/viewer/2022062703/55555f7fb4c9052b208b5416/html5/thumbnails/7.jpg)
A standard HTTP request
Response
<h1>Hello</h1>
Browser Server
hello..HTML
<h1>Hello</h1>
goodbye.HTML
<h1>Bye</h1>
![Page 8: Programming For Designers V3](https://reader036.fdocuments.net/reader036/viewer/2022062703/55555f7fb4c9052b208b5416/html5/thumbnails/8.jpg)
A standard HTTP request
Hello
![Page 9: Programming For Designers V3](https://reader036.fdocuments.net/reader036/viewer/2022062703/55555f7fb4c9052b208b5416/html5/thumbnails/9.jpg)
A CGI Request
Request
hello.PHP
Browser Server
hello.PHP
Echo “Hello”;
goodbye.PHP
Echo “Goodbye”;
![Page 10: Programming For Designers V3](https://reader036.fdocuments.net/reader036/viewer/2022062703/55555f7fb4c9052b208b5416/html5/thumbnails/10.jpg)
A CGI Request
Response hello.PHP
Echo “Hello”;
Browser Server
<h1>Hello</h1>
goodbye.PHP
Echo “Goodbye”;
![Page 11: Programming For Designers V3](https://reader036.fdocuments.net/reader036/viewer/2022062703/55555f7fb4c9052b208b5416/html5/thumbnails/11.jpg)
A CGI Request
hello.PHP
<?php echo “<h1>Hello</h1>”;?>
![Page 12: Programming For Designers V3](https://reader036.fdocuments.net/reader036/viewer/2022062703/55555f7fb4c9052b208b5416/html5/thumbnails/12.jpg)
A CGI Request
Hello
![Page 13: Programming For Designers V3](https://reader036.fdocuments.net/reader036/viewer/2022062703/55555f7fb4c9052b208b5416/html5/thumbnails/13.jpg)
Server Side vs Client Side
Javascript
Java
Flash
PHP
Java
ASP
Client Server
HTTP
![Page 14: Programming For Designers V3](https://reader036.fdocuments.net/reader036/viewer/2022062703/55555f7fb4c9052b208b5416/html5/thumbnails/14.jpg)
Sequences
echo “<p>Hello</p>”;
echo “<p>Goodbye</p>”;To Do:•Go Home•Make Tea•Wash Up
To Do:
![Page 15: Programming For Designers V3](https://reader036.fdocuments.net/reader036/viewer/2022062703/55555f7fb4c9052b208b5416/html5/thumbnails/15.jpg)
Variables
Name Price
John 16.50
![Page 16: Programming For Designers V3](https://reader036.fdocuments.net/reader036/viewer/2022062703/55555f7fb4c9052b208b5416/html5/thumbnails/16.jpg)
Variables
Name Price
Pete 16.50
![Page 17: Programming For Designers V3](https://reader036.fdocuments.net/reader036/viewer/2022062703/55555f7fb4c9052b208b5416/html5/thumbnails/17.jpg)
Variables
$price = 20;
$name = “John”;
echo “Hello $name, the price is £$price”;
$name = “Pete”;
echo “Hello $name, the price is £$price”;
$tax = $price * 0.15;
![Page 18: Programming For Designers V3](https://reader036.fdocuments.net/reader036/viewer/2022062703/55555f7fb4c9052b208b5416/html5/thumbnails/18.jpg)
Input
To Do:A PHP scriptGet
Post
DatabaseCookies
Files
Server Info
![Page 19: Programming For Designers V3](https://reader036.fdocuments.net/reader036/viewer/2022062703/55555f7fb4c9052b208b5416/html5/thumbnails/19.jpg)
Output
To Do:A PHP scriptHTML
Database Cookies
Files
![Page 20: Programming For Designers V3](https://reader036.fdocuments.net/reader036/viewer/2022062703/55555f7fb4c9052b208b5416/html5/thumbnails/20.jpg)
Hello $name
$name = $_REQUEST[‘your_name’];
echo “<p>Hello $name</p>”;
helloform.HTML
… … …<form action=“helloreply.php” method=“post”>
<label>Your Name</label>
<input type=“text” name=“your_name” /> <input type=“submit” />
</form>… … …
helloreply.PHP
<html> <head>…..</head> <body><?php
$name = $_REQUEST[‘your_name’];
echo “<p>Hello $name</p>”;
?></body><html>
![Page 21: Programming For Designers V3](https://reader036.fdocuments.net/reader036/viewer/2022062703/55555f7fb4c9052b208b5416/html5/thumbnails/21.jpg)
Expressions and operators
$counter + 1;
($quantity * $price) + $shipping
“blue” . “bird”
1 < 2
$dog == “Spot”
$price != 44;
![Page 22: Programming For Designers V3](https://reader036.fdocuments.net/reader036/viewer/2022062703/55555f7fb4c9052b208b5416/html5/thumbnails/22.jpg)
Selection – Hello maybe
$name = “Martin”;
if ($name != “John”)
{
echo “Hello!”;
}
else
{
echo “Goodbye!”;
}
To Do:Plan for todayif it is hot then go outsideotherwise stay in bed
![Page 23: Programming For Designers V3](https://reader036.fdocuments.net/reader036/viewer/2022062703/55555f7fb4c9052b208b5416/html5/thumbnails/23.jpg)
A more useful Hello maybe
$name = $_REQUEST[‘your_name’];if ($name != “Pete”){
echo “Hello!”;}else{
echo “Goodbye!”;}
hello.php?your_name=Maryhello.php?your_name=Pete
![Page 24: Programming For Designers V3](https://reader036.fdocuments.net/reader036/viewer/2022062703/55555f7fb4c9052b208b5416/html5/thumbnails/24.jpg)
Repetition (looping)
run a lap
until done 100 laps or completely knackered
$counter = 1;
while ($counter <= 10)
{
echo “$counter <br />”;
$counter = $counter + 1;
}
echo “Finished<br />”;
![Page 25: Programming For Designers V3](https://reader036.fdocuments.net/reader036/viewer/2022062703/55555f7fb4c9052b208b5416/html5/thumbnails/25.jpg)
Functions
function fill_kettle()
{
place kettle under tap;
turn on tap;
wait until kettle is full;
turn off tap;
}
fill_kettle();
![Page 26: Programming For Designers V3](https://reader036.fdocuments.net/reader036/viewer/2022062703/55555f7fb4c9052b208b5416/html5/thumbnails/26.jpg)
Hello function
hello();
function hello()
{
$name = $_REQUEST[‘name’];
echo “<p>Hello $name</p>”;
}
![Page 27: Programming For Designers V3](https://reader036.fdocuments.net/reader036/viewer/2022062703/55555f7fb4c9052b208b5416/html5/thumbnails/27.jpg)
Hello parameter
<?php
welcome(“Jane”);welcome($somebody);
function welcome($name){
$message = “<p>Hello $name</p>”; echo $message;
}
?>
![Page 28: Programming For Designers V3](https://reader036.fdocuments.net/reader036/viewer/2022062703/55555f7fb4c9052b208b5416/html5/thumbnails/28.jpg)
Databases
• Databases need code to retrieve data and translate into HTML
• SQL is the most popular language for asking databases for data
• PHP can talk to many databases using SQL but most often is paired with MySQL
![Page 29: Programming For Designers V3](https://reader036.fdocuments.net/reader036/viewer/2022062703/55555f7fb4c9052b208b5416/html5/thumbnails/29.jpg)
SQL
• SQL is used with other languages such as PHP
SELECT * FROM orders;
SELECT profile_pic FROM profiles WHERE profile_name = “Jimbo123”;
![Page 30: Programming For Designers V3](https://reader036.fdocuments.net/reader036/viewer/2022062703/55555f7fb4c9052b208b5416/html5/thumbnails/30.jpg)
Let’s Design an App
What have you done today?
Update
Cooked a curry
Went to work
Jogged 2 miles
![Page 31: Programming For Designers V3](https://reader036.fdocuments.net/reader036/viewer/2022062703/55555f7fb4c9052b208b5416/html5/thumbnails/31.jpg)
Twaddl Database
ID Twaddl
1 Argued with girlfriend – again!
3 Went to work
4 Cooked a curry
2 Jogged 2 miles
![Page 32: Programming For Designers V3](https://reader036.fdocuments.net/reader036/viewer/2022062703/55555f7fb4c9052b208b5416/html5/thumbnails/32.jpg)
Twaddl Main Program Flow
Handle posted twaddl
List twaddles
![Page 33: Programming For Designers V3](https://reader036.fdocuments.net/reader036/viewer/2022062703/55555f7fb4c9052b208b5416/html5/thumbnails/33.jpg)
Handle Posted Twaddl
Is submitted twaddle empty?
Insert twaddle into database
List twaddles
NoYes
Display an error message
![Page 34: Programming For Designers V3](https://reader036.fdocuments.net/reader036/viewer/2022062703/55555f7fb4c9052b208b5416/html5/thumbnails/34.jpg)
List Twaddles
Get list of twaddles from database
End Program
For each twaddle in list: Display twaddle
![Page 35: Programming For Designers V3](https://reader036.fdocuments.net/reader036/viewer/2022062703/55555f7fb4c9052b208b5416/html5/thumbnails/35.jpg)
Complications! An example.
• Ordinals: 1st 2nd 3rd 4th etc.• Mod: 53 % 10
function ordinal($number){
$last_digit = $number % 10;if ($last_digit == 1) $ord = “st”;elseif ($last_digit == 2) $ord = “nd”;elseif ($last_digit == 3) $ord = “rd”;else $ord = “th”;echo $number . $ord;
}
![Page 36: Programming For Designers V3](https://reader036.fdocuments.net/reader036/viewer/2022062703/55555f7fb4c9052b208b5416/html5/thumbnails/36.jpg)
Where from here?
PHP Lessons Online:
• http://uk3.php.net/tut.php
• http://www.webmonkey.com/tutorial/PHP_Tutorial_for_Beginners
Tuition