All Entries Tagged With: "example"
Displaying Content of a Text File in PHP
<?php
$file=’info.txt’;
$fobj=fopen($file,"r");
$text=fread($fobj, filesize($file));
echo("<h2><font color=’blue’>Displaying Content of a Text File</font><h2>");
echo("<br>");
echo("<font size=3>");
echo($text);
echo("</font>");
fclose($fobj);
?>
Creating Constructors with Classes in PHP
<?php
class student
{
var $name;
var $age;
var $grade;
function student($n,$a,$g)
{
$this->name=$n;
$this->age=$a;
$this->grade=$g;
}
function display_info()
{
echo("<p>Name [...]
Example process of creating classes and objects in PHP
<?php
class emp
{
var $name;
var $address;
var $dept;
function assign_info($n,$a,$d)
{
$this->name=$n;
$this->state=$a;
$this->dept=$d;
}
function display_info()
{
echo("<p>Employee [...]
Using Nested Functions in PHP
<?php
function msg()
{
echo("<center><h2>Displaying even
numbers</h2></center><p><p>");
function displayeven()
{
$ctr=0;
echo("<font size=4>");
for($i=2;$i<=100;$i+=2)
{
echo("$i ");
[...]
Example of User-Defined Function in PHP
<?php
echo("<center><h2>Displaying even numbers</h2></center><p><p>");
function displayeven()
{
$ctr=0;
echo("<font size=4>");
for($i=2;$i<=100;$i+=2)
{
echo("$i ");
$ctr++;
if($ctr%10==0)
{
echo("<p>");
[...]
Using the for Loop in PHP
<?php
echo("Prime Numbers between 1 and 30<p>");
//For loop from 1 to 30
for($var=1;$var<30;$var++)
{
$ctr=0;
for($k=2;$k<=$var/2;$k++)
{
$d=$var%$k;
if ($d == 0)
{
$ctr=1;
[...]
Using the while Loop in PHP
<?php
$a=2;
echo("<p>Even Numbers from 2 to 30<p>");
while ($a <=30)
{
echo("$a <br>");
$a=$a+2;
}
?>
Using the switch case Conditional Statement in PHP
<?php
//Initializing variables
$a = 10;
$b = 5;
echo("1. Addition <br>");
echo("2. Subtraction <br>");
echo("3. Multiplication <br>");
echo("4. Division <br>");
$ch=3;
switch ($ch)
{
case 1:
$d=$a+$b;
echo("The sum of the two numbers is $d");
break;
case 2:
$d=$a-$b;
echo("The difference of the two numbers is $d");
[...]
Find maximum of three numbers using IF ELSE in PHP
<?php
$x=10;
$y=20;
$z=30;
if($x > $y)
{
if($x > $z)
{
echo("The maximum number is ");
echo("$x<p>");
}
else
{
echo("The maximum number is ");
echo("$z<p>");
}
}
else
{
[...]
Example of IN and NOT IN SQL Queries
SELECT id
FROM stats
WHERE position IN (’Manager’, ‘Staff’)
SELECT ownerid, ‘is in both orders & antiques’
FROM orders, antiques WHERE ownerid = buyerid
UNION
SELECT buyerid, ‘is in antiques only’
FROM antiques WHERE buyerid NOT IN (SELECT ownerid FROM orders)