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++;
}
}
Assigment 4:
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
Using for loopwrite 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:
- <?php
- $date=DATE('D');
- switch($date){
- case 'Sun';
- echo "today is sunday";
- break;
- case 'Mon';
- echo "today is monday";
- break;
- case 'Tue';
- echo "today is tuesday";
- break;
- case 'Wed';
- echo "today is wednsday";
- break;
- case 'Thr';
- echo "today is thirsday";
- break;
- case 'Fri';
- echo "today is friday";
- break;
- case 'Str';
- echo "today is satursday";
- break;
- default;
- echo "invalid day";
- }
- ?>
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:
- <?php
- $date=DATE('D');
- switch($date){
- case 'Sun';
- echo "today is sunday";
- break;
- case 'Mon';
- echo "today is monday";
- break;
- case 'Tue';
- echo "today is tuesday";
- break;
- case 'Wed';
- echo "today is wednsday";
- break;
- case 'Thr';
- echo "today is thirsday";
- break;
- case 'Fri';
- echo "today is friday";
- break;
- case 'Str';
- echo "today is satursday";
- break;
- default;
- echo "invalid day";
- }
- ?>
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.
- <?php
- $a = " i love imdadullah";
- echo $a;
- ?>
- 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
- <?php
- $a=7;
- if($a==7){
- echo "condition is true";
- }
- else{
- echo "condition is false";
- }
- ?>
- if($a=$_POST['a']<=10){
- echo "your value is less than or equal to 10";
- }
- else if($a=$_POST['a']<=50){
- echo "your value is greater than 10 or equal to 50";
- }
- else if($a=$_POST['a']<=100){
- echo "you value is greater than 50 or equal to 100";
- }
- else{
- echo "your value is greater than 100";
- }
- }
- ?>
- </body>
- </html>
keep it up <3
ReplyDelete