Tuesday, 15 July 2014

Mixing PHP and HTML code

The concept of mixing  PHP and HTML means to combine both codes together without loosing their separate identity. Before getting started let's take a look at the following points.
  1. PHP is Server Side Code because it is executed or resolved on the server side, not in you browser.
  2. HTML is Client Side Code because it is executed in your browser.
Now the most important question is that how to keep separate identity of PHP code with HTML, the simple answer is, the PHP code always enclosed between two tags called Starting-tag and Ending-tag.
Any code written between these two tags are considered as PHP code, so don't forget to add these two tags when you start PHP code in HTML section. For further explanation let's take a look in the following example.
Please write the following code in your text editor and save the file as example.php or what ever you like the name but extension should be php.

<html>
<head>
<title>  Mixing PHP and HTML </title>
</head>
<body>


Hey! this is html code. <br>
 

<?php
echo "Yeh! but this is php code.";
?>


</body>
</html>


In above example
<?php and ?> are php starting and ending tags
echo is output command
Semicolon ";" at the end of echo command is called command terminator, without this terminator php unable to make decision where the current command is terminated and the new is started.

Sunday, 13 July 2014

Global Variable

A global variable is one that can be accessed from anywhere in the programming.

Each time when you declare a global variable you must keep it separate identity from the local variable because if you declared a variable as global and at the same time declared a variable with the same name as local one you simply create a logical error, so try to keep proper identification between global and local variables.

Scope of Global Variable




Sunday, 6 July 2014

PHP Variables

In general term

" A variable is a character or symbol that represents a certain value."

Suppose

A = 5
B = 2

Here
A and B are two variables
Variable A holds value 5
Variable B holds value 2

Types of PHP Variables

 Most common types of variables are given below.
  1. Local variables
  2. Global variables
  3. Static variables
  4. Function parameters

Monday, 30 June 2014

What is Relay

In electrical term,
"Relay is an electromagnetic switch which is operated by current to make or break the circuit."
It is extensively used in industry to make or break the connections.

Relay

Where:
A & B terminals are relay inputs.
COM is common terminal of switch.
NC is normally open terminal of switch.
NO is normally close terminal of switch.

Tuesday, 30 July 2013

Example of HTML PHP Comment

Type the following code in your text editor..

<HTML>
<HEAD>
<TITLE>Example of Comments</TITLE>
</HEAD>
<BODY>
<!-- html comment style -->

<?
// This is a single line PHP comment style.

# Shell type comment style.
/* This is a C style comment, we can use it for multiple lines 

this is suitable for multiple line comment */
?>

</BODY>
</HTML>


Now save this file as comment.php

Comment in PHP

Various types of syntax are used  to add comment in PHP.

Syntax 1

// this is single line comment in php code.

Syntax 2

# this is another style of comment in php code called shell-style.

Syntax 3


/* this is C-style comment in php code used for upto two lines */

Syntax 4

<!   example of html comment which is ignored by browser  >

Sunday, 28 July 2013

Print Quotient and Remainder in C++

// Write a C++ program that takes two values of x(dividend) and
// y(divisor) from user and prints quotient and remainder of x/y

#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    int x,y,q,r;
    cout<<"Enter dividend number x : ";
    cin>>x;
    cout<<"Enter divisor number y : ";
    cin>>y;

    cout<<"\n\n------------------------------------\n";
    cout<<" Quotient and Remainder of x/y \n";
    cout<<"------------------------------------\n";

    q = x / y ;
    r = x % y;
    cout<<"Quotient  = "<<q<<endl<<"Remainder = "<<r;
    getch();
}


Saturday, 27 July 2013

PHP Start and End tags

There are three basic types of PHP Start and End tags which is also called PHP Opening and Closing tags respectively.


Figure: PHP Starting and Ending Tags


Examples:

You can use any type of php tag in your script.

<?
echo "<P>Example of 1st type of PHP tag.</P>";
?>


<?php
echo "<P>Example of 2nd type of PHP tag.</P>";
?>


<script language="php">
echo "<P>Example of 3rd type of PHP tag.</P>";
</script>


Wednesday, 24 July 2013

Even Numbers in Descending Order

// Write a C++ program that prints odd numbers in
// descending order from a given range.

#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    int i,n;
    cout<<"Enter any number : ";
    cin>>n;
   
    cout<<"\n\n------------------------------------\n";
    cout<<" Even numbers in Descending Order \n";
    cout<<"------------------------------------\n";

    if( n%2 != 0 )
    n--;
    for( i = n ; i >= 0 ; i = i-2 )
    cout<<"         "<<i<<endl;
    getch();
}

Sunday, 21 July 2013

Even Numbers in Ascending Order

// Write a C++ program that prints even numbers in
// ascending order up to given range.


#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    int i,n;
    cout<<"Enter any number for ending range : ";
    cin>>n;
   
    cout<<"\n\n------------------------------------\n";
    cout<<" Even numbers in Ascending Order \n";
    cout<<"------------------------------------\n";

    for( i = 0 ; i <= n ; i = i+2 )
    cout<<"         "<<i<<endl;
    getch();
}

Odd Numbers in Ascending Order

// Write a C++ program that prints odd numbers in
// ascending order up to given number.

#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    int i,n;
    cout<<"Enter any number : ";
    cin>>n;
   
    cout<<"\n\n------------------------------------\n";
    cout<<" Odd numbers in Ascending Order \n";
    cout<<"------------------------------------\n";

    if( n%2 == 0 )
    n--;
    for( i = 1 ; i <= n ; i = i+2 )
    cout<<"         "<<i<<endl;
    getch();
}

Wednesday, 17 July 2013

Odd numbers in descending order

// Write a C++ program that prints odd numbers in 
// descending order from a given input.

#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    int i,n;
    cout<<"Enter any number : ";
    cin>>n;
   
    cout<<"\n\n------------------------------------\n";
    cout<<" Odd numbers in Descending Order \n";
    cout<<"------------------------------------\n";

    if( n%2 == 0 )
    n--;
    for( i = n ; i >= 1 ; i = i-2 )
    cout<<"  "<<i<<endl;
    getch();
}


Monday, 15 July 2013

Temperature Conversion

Convert Fahrenheit to Celsius

C = 5/9(F - 32)

Convert Celsius to Fahrenheit


F = 9/5(C + 32)


Convert Celsius to Kelvin


K = C + 273.15

Convert Kelvin to Celsius

C = K - 273.15

If you are interested in C++ programming, please visit the following links.

Kelvin to Celsius Conversion

// Write a C++ program to convert temperature from
// Kelvin to Celsius.

#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    float k,c;

    cout<<"\n------------------------------------\n";
    cout<<"  Kelvin to Celsius Conversion \n";
    cout<<"------------------------------------\n\n";

    cout<<"Enter the value of temp in Kelvin : ";
    cin>>k;
    c = k - 273.15 ;
    cout<<"\n\n Temp in Kelvin = "<<c;
    getch();
}


Celsius to Kelvin Conversion

// Write a C++ program to convert temperature from
// Celsius to Kelvin.

#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    float c,k;

    cout<<"\n------------------------------------\n";
    cout<<"  Celsius to Kelvin Conversion \n";
    cout<<"------------------------------------\n\n";

    cout<<"Enter the value of temp in Celsius : ";
    cin>>c;
    k = c + 273.15 ;
    cout<<"\n\n Temp in Kelvin = "<<k;
    getch();
}

Sunday, 14 July 2013

Farenheit to Celsius conversion

#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    float f,c;

    cout<<"\n------------------------------------\n";
    cout<<"  Farenheit to Celsius Conversion \n";
    cout<<"------------------------------------\n\n";

    cout<<"Enter the value of temp in Farenheit : ";
    cin>>f;
    c = (f-32)/1.8;
    cout<<"\n\n Temp in Celsius = "<<c;
    getch();
}

Celsius to Farenheit Conversion

#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    float c,f;

    cout<<"\n------------------------------------\n";
    cout<<"  Celsius to Farenheit Conversion \n";
    cout<<"------------------------------------\n\n";

    cout<<"Enter the value of temp in Celsius : ";
    cin>>c;
    f=(9/5)*c+32;
    cout<<"\n\n Temp in Farenheit = "<<f;
    getch();
}

Saturday, 13 July 2013

if else statement syntax

C++ "if" statement contains following elements.
  • Test expression
  • if body

Figure: if statement

The operation of "if" statement is explained by using flow chart.

Figure: if statement flow chart

if statement syntax

C++ "if" statement contains following elements.
  • Test expression
  • if body

Figure: if statement

The operation of "if" statement is explained by using flow chart.

Figure: if statement flow chart

Friday, 12 July 2013

do while loop syntax

C++ "do while loop" contains following elements.
  • Test expression
  • Increment expression
  • Loop body
 
Figure: do while loop

The operation of "do while loop" is explained by using flow chart.

Figure: do while loop flow chart