php

Web Eng-II

2/10/2015 By: Fazal Mabood Lecture 8

class work assigment:4 with while loop

 while loop
syntax
initilaization
while(testing/condition)
{
loop statements
incrementation
}
 write a parograme in whle loop to display first 10 natural number
<?php
$a=1;
while($a<=10)
{
echo $a "<br>";
$a++;
}
>?

Assigment 4:

<html>
<form name="imdad" method="GET" action="">
<table border="5px">
<tr>
<td><input type="text" name="a" placeholder="initilavalue"></td>
<td><input type="text" name= "b" placeholder="final"></td>
</tr>
<tr>
<td>odd number</td><td><input type="radio" name="radio1"></td></tr>
<tr>
<td>even number</td><td><input type="radio" name="radio2"></td>
</tr>
<tr>
<td>numbers from initial to final range</td><td><input type="radio" name="radio3"></td>
</tr>
<tr><td colspan="2" align=center><input type="submit" name="submit" value="show out put"></td></tr>
</table>
</form>
</html>

<?php
if (isset($_GET['submit']))
{
$ini=$_GET['a'];
$final=$_GET['b'];

while($ini<=$final){
if (isset($_GET['radio1'])){
if($ini%2!==0)
echo $ini."<br>";
$ini++;
}
else 
if (isset($_GET['radio2'])){
if($ini%2==0)
echo $ini."<br>";
$ini++;
}
else
if (isset($_GET['radio3'])){
echo $ini."<br>";
$ini++;
}
}
}
?>
<html>
<form name="imdad" methot="GET" action="">
<table border="5px">
<tr>
<td>enter a value for table</td><td><input type="text" name="a"></td>
</tr>
<tr>
<td align="center" colspan=2><input type="submit" name="submit1" value="submit"></td>
</tr>
</table>
</form>
</html>
<?php
if (isset($_GET['submit1'])){
$table=$_GET['a'];
$i=1;
while($i<=10){
echo $table."*".$i."=".($table*$i)."<br>";
$i++;
}
}


Web Eng-II

1/10/2015 By: Fazal Mabood Lecture 7

assigment:
today assigment

<html>
<form name="imdad" method="GET" action="">
<table border="5px">
<tr>
<td><input type="text" name="a" placeholder="initilavalue"></td>
<td><input type="text" name= "b" placeholder="final"></td>


</tr>
<tr>
<td>odd</td><td><input type="radio" name="radio1"></td></tr>
<tr>
<td>even</td><td><input type="radio" name="radio2"></td>
</tr>
<tr><td colspan="2" align=center><input type="submit" name="submit" value="show out put"></td></tr>
</table>
</form>

<?php
if (isset($_GET['submit']))
{
$ini=$_GET['a'];
$final=$_GET['b'];
for($i=$ini;$i<=$final;$i++){
if (isset($_GET['radio1'])){
if($i%2!==0)
echo $i."<br>";
}
else{
if (isset($_GET['radio2'])){
if($i%2==0)
echo $i."<br>";
}}
}
}
?>

Web Eng-II

19/9/2015 By: Fazal Mabood Lecture 6

Imdadullah is here to help you in php class work. if some body don't understand don't fell hesitate to contact me. i will guide you about class work and assignment. Remember me in your prayer's Using for loop

write a program in php to ask for a divisible of  a number from a specific range of divisibles?

<html>
<form name="imdad" method="GET" action="">
<table border=5px>
<tr>
<td>Divisible of</td><td><input type="text" name="value"></td>
</tr>
<tr>
<td>Divisible value from</td>
<td><input type="text" name="a" placeholder="set the initial number"></td>
</tr>
<tr>
<td>Divisible value up to</td>
<td><input type="text" name= "b" placeholder="set the final number"></td>
</tr>
<tr>
<td align="center" colspan="2"><input type="submit" name="submit" value="show out put"></td>
</tr>
</table>
</form>
<?php
if(isset($_GET['submit']))
{
$value=$_GET['value'];
$initial=$_GET['a'];
$final=$_GET['b'];
echo "The follwing is the divisible of  ".$value." But these are the divisible between".$initial." to ".$final."<br>."; 
for($x=$initial;$x<=$final;$x++)
{
if($value%$x==0){
echo  "$x<br>";

}
}
}
?> 
write a program in php to ask the initial and final value by the loop and display the range of values according.

<html>
<form name="imdad" method="GET" action="">
<table>
<tr>
<td><input type="text" name="a" placeholder="initilavalue"></td>
<td><input type="text" name= "b" placeholder="final"></td>
<td><input type="submit" name="submit" value="show out put"></td>
</tr>
</table>
</form>

<?php
if (isset($_GET['submit']))
{
$ini=$_GET['a'];
$final=$_GET['b'];
for($i=$ini;$i<=$final;$i++){
echo $i."<br>";
}
}
?>

Web Eng-II

16/8/2015 By: Fazal Mabood Lecture 5


Using for loop

write a program to display table of any given number.

<html>
<form name="imdad" method="GET" action="">
<table border="5px">
<tr>
<td>Enter the value for table you want</td><td><input type="text" name="a"></td>
</tr>
<tr>
<td align="center" colspan="2"><input type="submit" name="submit"</td>
</tr>
</table>
</form>
<?php
if(isset($_GET["submit"]))
{
$table=$_GET['a'];
echo "The table for $table is<br> ";
for($a=1;$a<=10;$a++)
{
echo $table. "*" .$a."=" ,($table*$a)."<br>";
}
}
?>
</html>

write a program to display the divisible and multiples of any given number

<html>
<form name="imdad" method="GET" target="">
<table border=5px>
<tr>
<td>
Enter the value to show you the divisible and multiple of the value</td><td><input type ="text" name="a"></td>
</tr>
<tr>
<td  align=center colspan=2>
<input type="submit" name="submit">
</td>
</tr>
</table>
</form>

<?php
if(isset($_GET['submit']))
{
$a=$_GET['a'];
echo "The number ".$a." is divisible by <br>";
for($x=1;$x<=100;$x++)
{
if($a%$x==0)
echo $x."<br>";
}
}
?>

<?php
if(isset($_GET['submit']))
{
$a=$_GET['a'];
echo "Multiple of ". $a." is<br>";
for($x=1;$x<=10;$x++){
echo ($a*$x)."<br>";
}
}
?>
</html>


Web Eng-II

11/8/2015 By: Fazal Mabood Lecture 4


loops:


1.for loop

2.while loop

3.do while loop

3. for each loop



for loop:

Syantax of for loop

for(initializing;test;incrementation)

{

loop statements

}

<?php
for($a=1;$a<=10;$a=$a+1)
{
echo  "my name is imdad<br>";
}
?>

Web Eng-II

10/8/2015 By: Fazal Mabood Lecture 3

Switch Statement .
switch statement:
syntax
swithch(condition/value)
{
case-:
{
break;
}
case-:
{

break;
}
default:
}


simple to check weather the day of week.
<?php
$date=DATE('D');
swithch($date)
{
case 'Sun';
{
echo "today is sunday";
break;
}
default:
echo"today is not sunday";
}
?>

 Today quiz:

  1. <?php
  2. $date=DATE('D');
  3. switch($date){
  4. case 'Sun';
  5. echo "today is sunday";
  6. break;
  7. case 'Mon';
  8. echo "today is monday";
  9. break;
  10. case 'Tue';
  11. echo "today is tuesday";
  12. break;
  13. case 'Wed';
  14. echo "today is wednsday";
  15. break;
  16. case 'Thr';
  17. echo "today is thirsday";
  18. break;
  19. case 'Fri';
  20. echo "today is friday";
  21. break;
  22. case 'Str';
  23. echo "today is satursday";
  24. break;
  25. default;
  26. echo "invalid day";
  27. }
  28. ?>



Web Eng-II

5/8/2015 By: Fazal Mabood Lecture 2

php variables .
  • A variable starts with the $ sign, followed by the name of the variable
  • A variable name must start with a letter or the underscore character
  • A variable name cannot start with a number
  • A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
  • Variable names are case-sensitive ($age and $AGE are two different variables)
  • The PHP echo statement is often used to output data to the screen.
Example.
  1. <?php
  2. $a = " i love imdadullah";   
  3. echo $a; 
  4. ?>
  • NOTE  first line of example /*alaka php ke mung wayu che da a value ( i love imdadullah )da. da a mung sara veriable day.. aw kala 6 mung veriable akhlu php ke nu $ sign wasara lagawal zarurey de*/
  • 2nd line of example /* was dalta mung varible wata khowalay day kho mung wayu che de variable la che mung kama value warkare pa screen rata display she mu hage dapara echo use kege. kha nu mung wata dase leku echo $a; mu pa screen munga  i love imdadullah show she*/

conditional statement.

In PHP we have the following conditional statements:
  • if statement - executes some code only if a specified condition is true
  • if...else statement - executes some code if a condition is true and another code if the condition is false
  • if...elseif....else statement - specifies a new condition to test, if the first condition is false
  • switch statement - selects one of many blocks of code to be executed
Example: 
  1. <?php
  2. $a=7;
  3. if($a==7){
  4. echo "condition is true";
  5. }
  6. else{
  7. echo "condition is false";
  8. }
  9. ?>
Today quiz in the class
  1. if($a=$_POST['a']<=10){
  2. echo "your value is less than or equal to 10";
  3. }

  4. else if($a=$_POST['a']<=50){
  5. echo "your value is  greater than 10 or equal to 50";
  6. }

  7. else if($a=$_POST['a']<=100){
  8. echo "you value is greater than 50 or equal to 100";
  9. }
  10. else{
  11. echo "your value is greater than 100";
  12. }
  13. }
  14. ?>
  15. </body>
  16. </html>
Notes written By Imdadullah

1 comment: