After 3 loops presenting Humara loop made by Sir Farooq

<?php

echo "Loop Start <br>";
//0 is value of $S
//20 is value of $E
HLoop(0,20);
echo "<br>Loop End ";
//$S shows Starting point
//$E Ending point
function HLoop($S,$E)
{
 echo $S." |";
 if($S>=$E)
 {
 return 0;
 }
 else
 {
 $S++;//increament in $S
 HLoop($S,$E);//Again HLoop Called
 }

}
?>
Advertisements

Recursion Lecture

Recursion:recusion

Recursion is the process of repeating items in a self-similar way.(wikipedia)

Recursion In PhP:

A function call itself is known as recursion in php.
Mostly in php if-else is used for breaking recursion function.

Simple Example:

ABC(1);
function ABC($E)
{
echo $E." |";
ABC(1);
}

In the above Example a simple function ABC() created .Where i give $E=1 and when browser/Compiler Enters in the function it will print 1 again and again until the browser show an Allowed memory size error.

Because when you call ABC() function inside in the funtion it Prints $E value which is 1 in this case .And after that you can see that we again call the funtion ABC() and it will again call itself again and again.

recursion error

Most important thing recursion is also use for making viruses.

Mathamatical Power function in Php without using pow()

 <html>
<head>
 <title>Power function</title>
 <style>
 #Sbutton
 {
 margin-right: 40px;

 }
 input[type="text"]
 {
 margin-bottom:5px;
 display: block;
 }
 h1
 {
 text-align: center;
 }

 </style>
</head>
<body>
<h1>Power Function</h1>
 <form action="pow.php" method="post">
 <input type="text" name="txtBase" placeholder="Enter Base">
 <input type="text" name="txtExponent" placeholder="Enter Exponent">
 <input type="submit" name="txtSubmit" id="Sbutton">

 </form>
</body>

</html>
<?php
if(isset($_POST['txtSubmit']))
{
 $Base = $_POST['txtBase'];//Base textfield name
 $Exp = $_POST['txtExponent'];//Exponent textfield name
 power($Base,$Exp);
}
function power($Base,$Exp)
{
 $A=$Base;
 for($a=1;$a<$Exp;$a++)
 {
 $A=$A*$Base;
 echo "$Base x ";
 }
 echo "$Base = $A";
}

?>

Salary Percentage in PHP

<!DOCTYPE html>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>Salary</title>
</head>

<body>
<form action=”index.php” method=”post”>
<table cellpadding=”5″ cellspacing=”5″>
<tr>
<td><input type=”text” name=”txtSalary”></td>
<td><input type=”submit” name=”ShowSalary”></td>
</tr>
</table>
</form>
<hr>
<table cellpadding=”5″ cellspacing=”5″>
<tr bgcolor=”#6699FF”><th>Expences</th><th>Percentage</th><th>Cost</th></tr>
<?php
if(isset($_POST[‘ShowSalary’]))
{
$Salary = $_POST[‘txtSalary’];
$Home = $Salary*0.10;
$Rashan = $Salary*0.10;
$Medical = $Salary*0.5;
$Travel = $Salary*0.5;
$Education = $Salary*0.5;
$Remaining = $Salary*0.60;

$CN = mysql_connect(“LocalHost”,”root”,””);
mysql_select_db(“Salary”,$CN);
mysql_query(“insert into tblSalary values (”,’$Salary’,’$Home’,’$Rashan’,’$Medical’,’$Travel’,’$Education’,’$Remaining’)”,$CN);
mysql_close($CN);

echo”<tr><td>Total</td> <td>100$</td> <td>$Salary. Rs</td></tr>”;
echo”<tr><td>House Rent</td> <td>10%</td> <td>$Home. Rs</td></tr>”;
echo”<tr><td>Rashan</td> <td>10%</td> <td>$Rashan. Rs</td></tr>”;
echo”<tr><td>Medical</td> <td>5%</td> <td>$Medical. Rs</td></tr>”;
echo”<tr><td>Travel</td> <td>5%</td> <td>$Travel. Rs</td></tr>”;
echo”<tr><td>Education</td> <td>5%</td> <td>$Education. Rs</td></tr>”;
echo”<tr><td>Remaining</td> <td>60%</td> <td>$Remaining. Rs</td></tr>”;
}

?>
</table>
</body>
</html>

Table import it in phpmyadmin tblsalary

Php MySql Connection

<?php
if(isset($_POST[‘btnSave’]))  //isset checked button Sent True or Null
{
$A = $_POST[‘txtName’];
$B = $_POST[‘txtPhone’];
$C = $_POST[‘txtEmail’];
$D = $_POST[‘txtNIC’];
//————————-//
$CN = mysql_connect(“LocalHost”,”root”,””);
mysql_select_db(“AirLineDB”,$CN);  //AirLineDB is Database name
mysql_query(“Insert into tblStudent values (”,’$A’,’$B’,’$C’,’$D’)”,$CN);  //tblStudent is Table Name
mysql_close($CN);
echo “Data Saved…”;

}
?>
<html>
<body>
<h2 align=center>Enter Student Information</h2>
<form action=”Register.php” Method=”POST”>
<table border=1 cellPadding=5 cellSpacing=5 align=center>
<tr>
<td bgcolor=aqua>Name</td>
<td><input type=Text name=txtName Required></td>
</tr>
<tr>
<td bgcolor=aqua>Phone</td>
<td><input type=Text name=txtPhone Required></td>
</tr>
<tr>
<td bgcolor=aqua>Email</td>
<td><input type=Text name=txtEmail Required></td>
</tr>
<tr>
<td bgcolor=aqua>N-I-C</td>
<td><input type=Text name=txtNIC Required></td>
</tr>
<tr>
<td bgcolor=aqua>.</td>
<td><input type=Submit name=btnSave Value=Save></td>
</tr>
</table>
</form>
</body>
</html>

Calculating the Note Change in C#

using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Text.RegularExpressions;

namespace Currency
{
class Program
{
static void Main(string[] args)             //Main Method
{
List<int> notes = new List<int>();
List<int> amounts = new List<int>() { 10, 20, 50, 100, 500 ,1000, 5000 };

BACK:
Console.Write(“Enter input : “); // Prompt
int line = Convert.ToInt32(Console.ReadLine());
Change(notes, amounts, 0, 0, line);
Console.ReadKey();
goto BACK;

}
static void Change(List<int> notes, List<int> amounts, int highest, int sum, int goal)
{
//
// See if we are done.
//
if (sum == goal)
{
Display(notes, amounts);
return;
}
//
// See if we have too much.
//
if (sum > goal)
{
return;
}
//
// Loop through amounts.
//
foreach (int value in amounts)
{
//
// Only add higher or equal amounts.
//
if (value >= highest)
{
List<int> copy = new List<int>(notes);
copy.Add(value);
Change(copy, amounts, value, sum + value, goal);
}
}
}

static void Display(List<int> notes, List<int> amounts)
{
foreach (int amount in amounts)
{
int count = notes.Count(value => value == amount);
Console.WriteLine(“{0} x {1}”,amount,count);
}
Console.WriteLine();
}
}
}

 

Output:

money