Academic Poster for Download:
https://drive.google.com/file/d/0B0dgI5sYlhnkTmRGeWxFVklhZTg/view?usp=sharing
Saturday, December 3, 2016
Tuesday, September 6, 2016
Condition Statement in PHP
Program is a set of instructions for computer to execute. It is important to tell the computer when to execute an instruction and when not to. Thus, the condition statement has become a very important code in programming language. A proper planned condition statement may make the computer execute "WISELY". An artificial intelligent nothing but a bunch of condition statement to help computer to decide the next move.Type of condition statement in PHP
- If (condition) { ….. }
- If (condition) { ….. } else { ….. }
- If (condition) { ….. } else if(condition) { ….. } else { ….. }
- switch (var) { case x: …..; break; case y: …..; break; }
If (condition) { ….. }
This is the simplest form of conditional statement. This statement will check whether the condition is TRUE to execute block of codes within the curly brace.
<?php
$age = $_POST['age'];
if($age>18){
echo "You are adult!";
}
}
?>
If (condition) { ….. } else { ….. }
This condition statement contain two possible states (TRUE or FALSE). This statement will check whether the condition is TRUE to execute the first block of code and otherwise execute the second block of code in the else block.
<?php
$age = $_POST['age'];
if($age>18){
echo "You are adult!";
}else{
echo "You are just a kid";
}
}else{
echo "You are just a kid";
}
?>
If (condition) { ….. } else if(condition) { ….. } else { ….. }
This condition statement contain multiple possible states. If the first condition is true, the first block of codes will be executed Otherwise, if second condition is met, the second block of codes will be executed.
<?php
$age = $_POST['age'];
if($age>0 and $age<=1){
echo "You are Infant!";
}else if($age>1 and $age<=3){
echo "You are toddler";
}else if($age>3 and $age<=18){
echo "You are child";
}else if($age>18){
echo "You are adult";
}
}else if($age>1 and $age<=3){
echo "You are toddler";
}else if($age>3 and $age<=18){
echo "You are child";
}else if($age>18){
echo "You are adult";
}
?>
switch (var) { case x: …..; break; case y: …..; break; }
This condition statement contain multiple possible states. If any of this condition is true, the case block of that particular code will be execute.
<?php
$menuOption = $_POST['option'];
switch($menuOption){
case 1: echo 'Show Record';
break;
case 2: echo 'Add Record';
break;
case 3: echo 'Delete Record';
break;
case 4: echo 'Update Record';
break;
default: echo 'Invalid Option';
break;
}
?>
Form and PHP code
Methods to send Form data
There are two methods to send user inputs to script:
POST method is a safer method as the inputs will be send by attaching to the trail of the HTTP protocol.
- GET
- POST
POST method is a safer method as the inputs will be send by attaching to the trail of the HTTP protocol.
Data passed from FORM
$_GET is an array contains values passed using GET method. Syntax: $_GET [name] where name is the name attribute of form element$_POST is an array contains values passed using POST method. Syntax: $_POST [name] where name is the name attribute of form element
Options to handling FORM with PHP:
- Separated form and PHP code.
- PHP code and form in a single PHP file
Separated form and PHP code.
The easiest way to handle user input is used separated form and script. In this case, you need to create a form in HTML file. And, in the action attribute specify the PHP file that handle input from this file.
form.html
<form action="process.php" method="get">
Age : <input type="text" name="age" />
<input type="submit" name="submit" />
</form>
process.php
<?php
echo $_GET['age'];
?>
form.html
<form action="process.php" method="get">
Age : <input type="text" name="age" />
<input type="submit" name="submit" />
</form>
process.php
<?php
echo $_GET['age'];
?>
PHP code and form in a single PHP file
In this option, the PHP file consists of two roles: display form and process the input. PHP file has to determined when to display a form and when to process the input. It is very critical as the PHP code cannot process the task if there is no data from the form. Thus, we need to check whether the user has submitted the form. If the user did not submit form, display form for user input. If the user has filled in the form and pressed the submit button, Then, PHP will process the inputs from user.
registration.php
<?php
if(isset($_POST['submit'])){
// process the task as the submit button is pressed
}else{
// Display the form if the submit is not detected.
?>
<form action="process.php" method="get">
Age : <input type="text" name="age" />
<input type="submit" name="submit" />
</form>
<?php
}
?>
registration.php
<?php
if(isset($_POST['submit'])){
// process the task as the submit button is pressed
}else{
// Display the form if the submit is not detected.
?>
<form action="process.php" method="get">
Age : <input type="text" name="age" />
<input type="submit" name="submit" />
</form>
<?php
}
?>
Fundamental of PHP
- PHP code must be enclosed within a block: <?php ……. ?>
- Multiple PHP blocks are allowed in a single document.
- HTML tags can be used within PHP document.
- PHP file can be only executed in web server. It cannot run as a normal HTML file in the local file system.
- End each statement with a semicolon (;)
- Variables start with $ and it is scalable type (no need to declare before used)
- Variable name cannot start with number and it can be any alphanumeric value after the first character.
- echo is function that can print output to browser
- Form is an user interface that accept users input for server to process.
- Form must contains two attributes: action and method. Action attribute specified the script or program that will handle the input. Method is the sending method used (GET or POST). And, a submit button that will do the sending according to these two attributes.
PHP code must be enclosed within a block: <?php ……. ?>
HTML tags do not work within the PHP block. It must use echo function to output them to the browser.
<?php
echo "<H1>Heading Text</H1>";
echo "<P>Paragraph</p>";
?>
<H2>Sub Heading Text</H2>
<p>Paragraph in Sub section</p>
<?php
echo "<H1>Heading Text</H1>";
echo "<P>Paragraph</p>";
?>
<H2>Sub Heading Text 1</H2>
<p>Paragraph in Sub section</p>
<?php
echo "<H2>Sub Heading Text 2</H2>";
echo "<p>Paragraph in Sub section</p>";
?>
<?php
echo "<H1>Heading Text</H1>";
echo "<P>Paragraph</p>";
?>
<H2>Sub Heading Text</H2>
<p>Paragraph in Sub section</p>
Multiple PHP blocks are allowed in a single document.
HTML tags can be used within PHP document.
End each statement with a semicolon (;)
<?php
echo "<H1>Heading Text</H1>";
echo "<P>Paragraph</p>";
?>
<H2>Sub Heading Text 1</H2>
<p>Paragraph in Sub section</p>
<?php
echo "<H2>Sub Heading Text 2</H2>";
echo "<p>Paragraph in Sub section</p>";
?>
Variables start with $ and it is scalable type (no need to declare before used)
Variable name cannot start with number and it can be any alphanumeric value after the first character.
echo is function that can print output to browser
<?php
$B2B = true;
// $1MDB = "News"; <- Invalid variable start with number
$age = 25;
$name = "Johnson";
$years = 3.5;
echo "Name : ".$name."<br />Age : ".$age;
Form is an user interface that accept users input for server to process.
Form must contains two attributes: action and method. Action attribute specified the script or program that will handle the input. Method is the sending method used (GET or POST). And, a submit button that will do the sending according to these two attributes.
<form action="process.php" method="get">
Age : <input type="text" name="age" />
<input type="submit" name="submit" />
</form>
Wednesday, April 25, 2012
Decimal to Binary - JavaScript
The typical way to convert a decimal number to binary number is to divide the decimal number (the dividend) by 2 (the divisor) and the obtained quotient will be pass on and divide by 2 again until the quotient reached 0. Then, the remainder will become the binary number of the decimal number.
From the illustration, the binary of 64 is 1000000 (remainder from bottom to top). The same logic apply to decimal to hexadecimal as well.
Programming is a process of transferring observed logic into computer instructions. With the logic we observed from the above illustration, we can write a JavaScript function:
function dec2bin(num)
{
var dividend = num;
var divisor = 2;
var quotient = dividend;
var remainder;
var binary = [];
while(quotient>0)
{
remainder = quotient%divisor;
quotient = Math.floor(quotient/divisor);
binary.unshift(remainder);
}
return binary.join("");
}
In the function, it accept a decimal number. Then, assign this number to dividend and to quotient as well. We create an iteration statement to loop the process of division until the quotient is 0. The remainders are added into an array called binary. Finally, return the binary value as string to the program.
| Decimal Number : | |
| Binary Number : | |
From the illustration, the binary of 64 is 1000000 (remainder from bottom to top). The same logic apply to decimal to hexadecimal as well.
Programming is a process of transferring observed logic into computer instructions. With the logic we observed from the above illustration, we can write a JavaScript function:
function dec2bin(num)
{
var dividend = num;
var divisor = 2;
var quotient = dividend;
var remainder;
var binary = [];
while(quotient>0)
{
remainder = quotient%divisor;
quotient = Math.floor(quotient/divisor);
binary.unshift(remainder);
}
return binary.join("");
}
In the function, it accept a decimal number. Then, assign this number to dividend and to quotient as well. We create an iteration statement to loop the process of division until the quotient is 0. The remainders are added into an array called binary. Finally, return the binary value as string to the program.
Monday, April 23, 2012
AutoComplete feature in Browser
In order to save your time of typing repeating phrase such as user name, password, search string or some common fields that you often used, browser has include a feature called AutoComplete.
AutoCompete or sometime called AutoFill has been included in HTML 5. However, not all of the browsers supported this feature. For Mozilla Firefox, it is available from version 4 and above. And, Internet Explorer includes this feature from version 5 and above.
In Mozilla FireFox, you may enable the AutoComplete feature by configure the history setting under privacy tab. It is accessible from Tools > Options then select Privacy tab. Under the History block, choose Use custom settings for history option. And make sure you checked the checked box of Remember search and form history.
In Internet Explore, select Tools > Internet Options, then select Content tab. To enable the AutoComplete feature checked the AutoComplete checked box.
If you are using AutoComplete feature in ASP.NET, most likely you would like to enable this feature in your respective browsers.
AutoCompete or sometime called AutoFill has been included in HTML 5. However, not all of the browsers supported this feature. For Mozilla Firefox, it is available from version 4 and above. And, Internet Explorer includes this feature from version 5 and above.
In Mozilla FireFox, you may enable the AutoComplete feature by configure the history setting under privacy tab. It is accessible from Tools > Options then select Privacy tab. Under the History block, choose Use custom settings for history option. And make sure you checked the checked box of Remember search and form history.
In Internet Explore, select Tools > Internet Options, then select Content tab. To enable the AutoComplete feature checked the AutoComplete checked box.
If you are using AutoComplete feature in ASP.NET, most likely you would like to enable this feature in your respective browsers.
ASP.NET vs PHP
It is quite normal that people has confusion between ASP.NET and PHP.
In fact, ASP.NET is a subset of .NET Framework and PHP is a server site
programming language. At the end, they may take part in developing web
application but there are not the same.
.NET Framework is a big set of classes and libraries that have been created for developing all sorts of application; such as Windows Standalone Application, Dynamic Link Library or Web Application. And, ASP.NET is a subset of this "big family". ASP.NET contains classes and libraries that related to web development.
.NET Framework consists of two parts; Framework Class Library and Common Language Runtime. In fact, it is quite similar to JAVA. The concept behind .NET Framework is to build a cross architecture application that will split the process into compiling and running code in two different mode. Let take a look at the JAVA work flow diagram.
A JAVA source code with file extension of .java is compiled into a bytecodes file with file extension of .class. And the .class object file can be executed by JVM (Java Interpreter). It is a great concept from JAVA creator to separate the code from the machine. Thus, the task of communicating with different type of CPU architecture has been passed to JVM and class file will be able to run on different type of platform without modifying the source code and re-compilation depend on architecture is not needed.
In .NET, the similar concept is adapted in order to achieve this. Let take a look at the diagram above. It is a typical process of a .NET workflow. The source code will be compiled into MSIL (Microsoft Intermediate Language). And upon execution, it will be compiled by JIT compiler, resided in .NET engine, into a native code that can be executed by that particular machine.
For ASP.NET, the common programming language being used are C# and VB.NET. The source code of these program will be compiled by different language compiler (as C# source code can be only understood by C# compiler) stated in the page directive of the top of the aspx file. This will generate a Intermediate Language file. Then, it will be executed after compile by JIT into a native code.
I hope it will be useful to those person who just wanted to start to learn .NET or ASP.NET development. In short, you may compare C# with ASP.NET vs PHP but not ASP.NET vs PHP.
.NET Framework is a big set of classes and libraries that have been created for developing all sorts of application; such as Windows Standalone Application, Dynamic Link Library or Web Application. And, ASP.NET is a subset of this "big family". ASP.NET contains classes and libraries that related to web development.
.NET Framework consists of two parts; Framework Class Library and Common Language Runtime. In fact, it is quite similar to JAVA. The concept behind .NET Framework is to build a cross architecture application that will split the process into compiling and running code in two different mode. Let take a look at the JAVA work flow diagram.
A JAVA source code with file extension of .java is compiled into a bytecodes file with file extension of .class. And the .class object file can be executed by JVM (Java Interpreter). It is a great concept from JAVA creator to separate the code from the machine. Thus, the task of communicating with different type of CPU architecture has been passed to JVM and class file will be able to run on different type of platform without modifying the source code and re-compilation depend on architecture is not needed.
In .NET, the similar concept is adapted in order to achieve this. Let take a look at the diagram above. It is a typical process of a .NET workflow. The source code will be compiled into MSIL (Microsoft Intermediate Language). And upon execution, it will be compiled by JIT compiler, resided in .NET engine, into a native code that can be executed by that particular machine.
For ASP.NET, the common programming language being used are C# and VB.NET. The source code of these program will be compiled by different language compiler (as C# source code can be only understood by C# compiler) stated in the page directive of the top of the aspx file. This will generate a Intermediate Language file. Then, it will be executed after compile by JIT into a native code.
I hope it will be useful to those person who just wanted to start to learn .NET or ASP.NET development. In short, you may compare C# with ASP.NET vs PHP but not ASP.NET vs PHP.
Subscribe to:
Posts (Atom)


