Ad here

Showing posts with label Learn PHP. Show all posts
Showing posts with label Learn PHP. Show all posts

Monday, December 15, 2014

PHP HyperTextPreprocessor Tutorial Point Learn Easily PHP ( Part 2 )

Conditional statements :-
1.if (one way selection )
2.if else(two way selection )
3.if else if
4. switch case ( 3 & 4 both are multiway selection )

If:-

<?php        
$n=8;
If ($n==10)
{
Echo” value is 10”;
}
?>
If else:-
<?php
$p=50;
if(condition )
{
echo" statement 1";
}

 else
{
echo" statement 2";
}

?>
If else if :-

<body>
<?php
$p=50;
if(cond 1)
{
echo" statement 1";
}

 else if (cond 2)
{
echo" statement 2";
}
 else if (cond 3)
{
echo" statement 3";
}
else if(cond 4)
{
echo" statement 4";
}
else  
{
echo" statement 5";
}
?>

Switch Case:-
<body>
<?php
 $ch="a";
$a=10;
$b=5;
switch ($ch){
 case 'a':
 {
Case a formula
break;
 }
  case 'b':
 {
Case b formula
break;
 }
  case 'c':
 {
Case c formula
break;
 }
 default:
 {
 echo" you entered wrong value ";
 break;
 }
 }
Q1.Enter two numbers and find out greatest no. using if else?
Solution Code:-
<title>rahuljaincse.blogspot.com</title>
</head>
 <body>
<?php
$b=20;
if($b>18)
{
echo"person is eligible for voting:".$b;
}
else
{
echo"person is not eligible for the voting ";
}
 ?>
 </body>
Q2.Enter any age of person and find out person is eligible for voting or not?
Solution Code:-
<title>rahuljaincse.blogspot.com</title>
</head>
 <body>
<?php
$b=10;
if($b%5==0)
{
echo"your digit is divisible by 5:";
}
else
{
echo"your digit is  not divisible by 5 ";
}
 ?>
 </body>
</html>
Q3.Enter any digit and find out digit is devisible  by 5 or not?
<?php
$a=10;
If($a%5==0)
{
Echo “number is devisible by 5”;
}
Else
{
Echo “number is not devisible by 5”;
}
 ?>
Q4.Enter any percentage of students and print student belongs to which category?
80%---------A+
70-80%--------A
60-70%----------B+
50- 60%------------B
40-50%-----------------C
Less than 40 -----------Fail
Solution code:-
<title> rahuljaincse.blogspot.com</title>
</head>
 <body>
<?php
$p=50;
if($p>80)
{
echo" grade is A+";
}
 else if ($p<=80&&$p>70)
{
echo" grade is A";
}
 else if ($p<=70&&$p>60)
{
echo" grade is B+";
}
else if($p<=60&&$p>50)
{
echo" grade is B";
}
else if($p<=50&&$p>40)
{
echo" grade is C";
}
 else if  ($p<=40)
{
echo" grade is Fail";
}
?>
 </body>
</html>
 Q5.calculate area of circle ,Rectangle ,and triangle using Switch case?  
Solution Code:-
<title>rahuljaincse.blogspot.com</title>
</head>
<body><?php
 $ch="circle";
$a=10;
$b=5;
switch ($ch){
 case 'triangle':
 {
 $c=1/2*$a*$b;
 echo"area of triangle is".$c;
 break;
 }
  case 'circle':
 {
 $c=3.14*$a*$a;
 echo"area of circle is".$c;
 break;
 }
  case 'rectangle':
 {
 $c=$a*$b;
 echo"area of rectangle  is".$c;
 break;
 }
 default:
 {
 echo" you entered wrong value ";
 break;
 }
 }

PHP HyperTextPreprocessor Tutorial Point Learn PHP Easily ( Part 1 )

 
 HyperText Preprocessor 

It is Previously called   personal home page.
For working with php there are some softwares
For Linux OS Users LAMP (Linux Apache My Sql PHP)
FOR Windows OS  Uers WAMP (Windows Apache My Sql PHP)
And for all OS  Common one  is XAMPP
(Extensible Apache MySql PHP Perl )
For Working In Any Type Of OS there are few steps before actual php.
Step 1.      Install XAMPP
Step 2.      Install Dreamweaver
In Dreamweaver click on file ->new->Dynamic page->PHP.
You Save your files in XAMPP ->htdocs->your File name .php
Or
XAMPP ->htdocs->Your Folder (If you create )->your File name .php
And open your code on browser by
or

php  is loosely coupled language or we say that language +Technology.
Under the  HTML  our code of php  is running in the tags of  <body> .

<!DOCTYPE html ">
<head>
<title> rahuljaincse.blogspot.com </title>
</head>
<body>
<?php
 ____________________________________________________
(Code of php)
?>
</body>
</html>
Let we starts from a simple Example:-
<!DOCTYPE html ">
<head>
<title> rahuljaincse.blogspot.com </title>
</head>
<body>
<?php
echo “Good Morning”;//echo is for print
?>
</body>
</html>
Our out put on the Browser  is:-  Good Morning
---------------------------------------------------------------------------------------------
               Operators
Operators are of Three Types
1.Uniary
 (contains of increment ++,decrement--,uniary+,uniary-)
2.Binary
(1.airthmatic +,-,*,/,%
2. relational <,>.<=,>=,==,===,!=
3.assignment =)
3.Ternary
(logical &&)
Let See Some Solved Examples :-
Q1. Enter Two Values And print Substration, Multiplication& devision of two values?
Solution Code:-
<title>rahuljaincse.blogspot.com</title>
</head>
<body>
<?php
$a=5;
$b=3;
$s=$a-$b;
echo "substraction is=".$s;
echo"<br>";
$a=5;
$b=3;
$m=$a*$b;
echo "multiplication is=".$m;
echo"<br>";
$a=5;
$b=3;
$d=$a/$b;
echo "division  is=".$d;
?>
</body>
</html>
Q2.Enter Radius of circle & print area of circle?
Solution code:-
<?php
$a=your radius ;
 $c=3.14*$a*$a;
 echo"area of circle is".$c;
 ?>
Q3.Enter five marks of students and print percentage sheet of student?
<title> rahuljaincse.blogspot.com </title>
</head>
<body>
<?php
$a=45;
$B=75;
$C=85;
$D=55;
$E=33;
$P=($a+$B+$C+$D+$E)/5;
echo"percentage of students is =".$P;
?>
</body>
</html>
Q4.Enter any value and print square and cube of value?
<title> rahuljaincse.blogspot.com </title>
</head>
<body>
<?php
$a=45;
$sq=$a*$a;
echo"square is =".$sq."<br>";
$b=45;
$cu=$b*$b*$b;
echo"square is =".$cu;
?>
</body>
</html>
Q5.Enter Two values & findout smallest value using ternary operator?
<title> rahuljaincse.blogspot.com </title>
</head>
 <body>
<?php
$a=45;
$b=35;
$comp=($a>$b?$a:$b);
echo"greatest num is =".$comp;
?>
</body>
</html>
Q6.Enter any number and find out no. is positive or negative using conditional operation?
</head>
<body>
<?php
$a=45;
con=($a>=0?"pos":"neg");
echo" num is ".con;
?>
</body>
</html>
Q7.Enter Any digit & find out digit is single or more than single digit using conditional operations?
<title> rahuljaincse.blogspot.com </title>
</head>
<body>
<?php
$a=45;
$con=($a/10=0?"single":"not single ");
echo" num is ".$con;
?>
</body>
</html>
Q8.Enter Any year and find out year is leap year or not leap year?
<title> rahuljaincse.blogspot.com </title>
</head>
<body>
<?php
$a=2000; 
$year=($a%4==0?"leap year":"non leap year");
echo"year is=".$year;

?>
</body>
</html>