What we learned on Week 3 of ITC280 Class...
1. We don’t need a closing php tag if there are no conflicts.
<? php
echo "does this work?";
2. A function that has data passed to it as a parameter.
$myPay = 50000;
areYouHappy(140000);
function areYouHappy($myPay)
{
if($myPay >= 110000)
{
echo "I'm Happy!";
}else{
echo "Not so Happy!";
}
}
3. We can use curly braces to identify the variable - with backslash added to escape dollar sign
echo "I'm Happy with the \${$myPay}!";
4. We can pass in a variable via the keyword global.
$myPay = 50000;
areYouHappy();
function areYouHappy()
{
global $myPay;
if($myPay >= 110000)
{
echo "I'm Happy with the \${$myPay}!";
}else{
echo "Not so Happy with the \${$myPay}!";
}
}
5. Use the keyword return to pass data out of a function.
$myPay = 50000;
echo areYouHappy();
function areYouHappy()
{
global $myPay;
if($myPay >= 110000)
{
return "I'm Happy with the \${$myPay}!";
}else{
return "Not so Happy with the \${$myPay}!";
}
}
6. We can pass the data in as a parameter, and add br tags for readability.
$myPay = 50000;
echo areYouHappy($myPay);
echo areYouHappy(5);
echo areYouHappy(140000);
echo areYouHappy(30);
function areYouHappy($myPay)
{
if($myPay >= 110000)
{
return "I'm Happy with the \${$myPay}!<br />";
}else{
return "Not so Happy with the \${$myPay}!<br />";
}
}
7. Text is the default type attribute for the input element.
First Name: <input name="FirstName" />
8. An example of data in a querystring
forms1.php?FirstName=Leopaul
9. If we have more than one piece of data, it is separated by ampersand.
forms1.php?FirstName=Leopaul&LastName=DelRosario
10. If a value has a space, it is replaced with a plus sign.
FirstName=Leo+Paul&LastName=Del+Rosario
11. Our first web application.
if(isset($_POST['FirstName']))
{
echo $_POST['FirstName'];
}
12. Our first REAL web application.
<html>
<body>
<?php
if(isset($_POST['FirstName']))
{
echo $_POST['FirstName'];
echo '<br /><a href="forms2.php">RESET</a>';
}else{
?>
<form action="forms2.php" method="post">
First Name: <input type="text" name="FirstName" /><br />
Last Name: <input type="text" name="LastName" /><br />
<input type="submit" />
</form>
<?php
}
?>
</body>
</html>
13. Example of a superglobal. It gives us the current file name.
$_SERVER['PHP_SELF']
14. Force cast data to an integer
$myTires = (int)$_POST['Tires'];//forced cast to int
NOTES:
Sadly, my scores at Pop Quiz # 4 and Test # 3 are badly. For Pop Quiz # 4, I got 67% then on Test # 3, it's a 50%. Can't believe that most of the questions here are extremely difficult. I tried looking back at past lessons but the questions are too complicated to answer. Next time, I should remain focused on my class in order to get a better grade.
Speaking of which, I am currently working on Assignment # 3, which is the Troubleshooting Exercise. Due Monday, Apr. 23rd. In class, we only finished 5 out of 10 errors to find on this assignment. The trouble is, how can I find the remaining five errors?
Anyway, Mr. Newman set up the fixed version but the link is broken. I e-mailed him to get this link to the fixed "adder.php" page fixed so I can get the five remaining errors found. God, help us...
SCORES:
Pop Quiz # 4 - 7/10 (67%)
Test # 3 - 9/18 (50%)
1 comment:
Leopaul,
Excellent job on A3!
If you believe a particular test question to be hard to interpret please send an email and let me know you have a question about one of the test questions.
I can usually send a hint on where to look in the book or on the class website.
There will be extra credit opportunities to make up the lost points.
Thanks for working so hard!
Bill
Post a Comment