Blogroll

photoshop cs6 html 5 css php seo backlinks

adsense

Smarty Template Engine Step by Step Tutorial

Smarty has focused on how to help you make an high-performance, scalability, security and future growth application.

JavaScript was designed to add interactivity to HTML pages

JavaScript’s official name is ECMAScript, which is developed and maintained by the ECMA International organization.

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Friday, 7 February 2014

Learn Php conditions (If, if else, if else else, switch else)

Conditions are used to execute part of a script only if some predefined requirements (conditions) are fulfilled. For example, a condition could be that a date must be after January 1, 2012 or that a variable is greater than 7.

If...

The first type of condition we will look at is documentationif, which has the following syntax:
 if (condition) {
    statement
 }
 
 
Again, the syntax is very close to ordinary English: If a condition is met, then execute something. Let's look at a simple example:
 <html>

 <head>
 <title>Loops </title>
 </head>
 <body>

 <?php

 $x = 2;

 if ($x > 1) {
    echo "<p>variable $x is greater than 1 </p>";
 }
  
 ?>

 </body>
 </html>
 
 

if ... else ...

The next type of condition will want to look at is documentationelse , which may be presented in the following form:
 
 if (condition) {
    statement
 }
 else {
    statement
 }

 
Again, the syntax is very close to ordinary English: if a condition is met execute something or else execute something else.
, you learned how to find the number of a month. In the following example, we will use the month number in an documentationif documentationelse condition to find out what season it is:
 <html>
 <head>
 <title>Conditions</title>
 </head>
 <body>

 <?php

 if (date ("m") == 3) {
    echo "<p>Now it's spring!</p> ";
 }
 else {
    echo "<p>I do not know what season it is!</p> "; 
 }

 ?>

 </body>
 </html>
 
 
As you can see, this condition is not a particularly smart condition - it only works when it's March!
However, there are plenty of ways to improve the condition and make it more precise. Below are listed comparison operators that can be used in the condition:
== Equals
< Less than
> Greater than
<= Less than or equal to
>= Greater than or equal to
!= Not equal to
In addition, there are some logical operators:
&& And
|| Or
! Not
The operators can be used to develop more precise conditions, so now we can expand the above example to include all the spring months:
 <html>
 <head>
 <title>Conditions</title>

 </head>
 <body>

 <?php
 
 if (date("m") >= 3 && date("m") <= 5) {
    echo "<p> Now it's spring!</p> ";
 }
 else {
    echo "<p> Now it's either winter, summer or autumn!</p> ";
 }
  
 ?>

 </body>
 </html>

 
 
Let's take a closer look at the extended condition:
 date("m") >= 3 && date("m") <= 5 
 
The condition can be translated into:
 If the month is greater than or equal to 3,
 and the month is less than or equal to 5
 
 
Smart, eh? Operators play a significant role in many different parts of PHP.
But it still only works with March, April and May. All other months are not yet covered by the condition. So let's try to develop the condition a little more.

if ... elseif ... else...

Using documentationelseif, we can expand the condition and make it work for all months:
 <html>
 <head>
 <title>Conditions</title>

 </head>
 <body>

 <?php
 
 if (date("m") >= 3 && date("m") <= 5) {
    echo "<p>Now it's spring!</p>";
 }

 elseif (date("m") >= 6 && date("m") <= 8) {
    echo "<p>Now it's summer!</p>";
 }

 elseif (date("m") >= 9 && date("m") <= 11) {
    echo "<p>Now it's autumn!</p>";
 }

 else {
    echo "<p>Now is winter!</p>";
 }
  
 ?>

 </body>
 </html>

 
 
To write conditions is all about thinking logically and being methodical. The example above is pretty straightforward, but conditions can get very complex.

switch ... case

Another way of writing conditions is to use the documentationswitch method:
 switch (expression) {
 
 case 1: 
    statement
    break; 
 case 2: 
    statement
    break; 
 default:
    statement
    break;
 }
 
 
This method is based on an expression and then lists different "answers" or "values" with related statements. The easiest way to explain the method is to show an example.
As you may remember from lesson 4, the function documentationdate("w") returns the current weekday. This can be used in an example where we write the name of the day (instead of a number):
 <html>
 <head>
 <title>Conditions</title>
 </head>
 <body>

 <?php
 
 switch(date("w")) {
  
 case 1:
    echo "Now it's Monday";
    break;
 case 2:
    echo "Now it's Tuesday";
    break;
 case 3:
    echo "Now it's Wednesday";
    break;
 case 4:
    echo "Now it's Thursday";
    break;
 case 5:
    echo "Now it's Friday";
    break;
 case 6:
    echo "Now it's Saturday";
    break;
 default:
    echo "Now it's Sunday";
    break;
  
 }
  
 ?>

 </body>
 </html>
 
 
Often documentationswitch can be a good alternative to documentationif documentationelse conditions. What you should use in a given situation depends on which method you find easiest and most logical. Making your scripts logical and clear can be a great challenge.

How to create Loops in php? php loops

In PHP, it is possible to manage the execution of scripts with different control structures. In this lesson, we will look at loops. Loops can be used to repeat parts of a script a specified number of times or until a certain condition is met.

"while" loops

The syntax for a documentationwhile loop is:
 while (condition) {
  Statement
 } 
 
 
The syntax can almost be directly translated into English: do something while a condition is met.
Let's look at a simple example:
 <html>
 <head>
 <title>Loops</title>

 </head>
 <body>

 <?php

 $x = 1;
  
 while ($x <= 50) {
    echo "<p>This text is repeated 50 times</p>";
    $x = $x + 1;
 }
 ?>

 </body>

 </html>
 
 
In the example, a variable named "$x" is used. As you can see, variables in PHP always start with a "$" character. It's easy to forget this at first, but it's absolutely necessary to remember or else the script doesn't work.
Apart from that, the example is almost self-explanatory. First the variable $x is set to be equal to 1. Then the loop asks the server to repeat the text while $x is less or equal to 50. In each loop, the variable $x will be increased by 1.

"for" loops

Another way to make a loop is with documentationfor on the form:
 
 for (Initialization; Condition; Step) {
   Statement
 }
 
 
The statement is repeated as long as 'Initialization' + 'Step' meets the 'Condition'. If that doesn't make sense, look at this example:
 <html>
 <head>

 <title>Loops</title>
 </head>
 <body>

 <?php

 for ($x=0; $x<=50; $x=$x+5) {
    echo '<p>variable $x is now = ' . $x . '</p>';
 }
 ?>

 </body>
 </html>
 
 
In the example above, $x is growing with the value 5 in each loop. The loop will continue as long as $x is below or equals 50. Also note how the value $x is used as part of the sentence.
Here is another example:
 <html>
 <head>

 <title>Loops</title>
 </head>
 <body>

 <?php

 for ($x=1; $x<=6; $x=$x+1) {
    echo "<h" . $x . ">Heading level " . $x . "</h" . $x . ">";
 }
 ?>

 </body>
 </html>
 
 
Do you get it? First we set the value of $x to 1. Then in each loop, we write a heading at level $x (h1, h2, h3, etc.) until $x is equal to six.

Loops within loops

In principle, there are no limitations on how loops can be used. For instance, you can easily put loops inside loops and thereby create many repeats.
But be careful! PHP becomes slower the more complicated and extensive the scripts. For instance, look at the next example where, with three loops, we can write over 16 million colors!
In order not to make the page slow, we have drastically reduced the number by putting the step to 30 and thereby limited the number of colors to 512.
 <html>

 <head>
 <title>Loops </title>
 </head>
 <body>

 <?php
 
 for ($intRed=0; $intRed<=255; $intRed=$intRed+30) {

    for ($intGreen=0; $intGreen<=255; $intGreen=$intGreen+30) {

       for ($intBlue=0; $intBlue<=255; $intBlue=$intBlue+30) {
  
    $StrColor = "rgb(" . $intRed . "," . $intGreen . "," . $intBlue . ")";
    
    echo "<span style='color:" . $StrColor . "'>" . $StrColor . "</span>";
  
       }
    }
 }
 ?>

 </body>
 </html>
 
 

PHP Time and date functions, Working with time and dates

In this lesson, we will try to look at the many different options for working with time and dates in PHP. We went through some very simple examples in the previous lesson mostly to show you what PHP is. In this lesson, we will take a closer look at the documentationdate function.

Time and date functions

PHP provides a wide range of funtions in relation to time and date. In this lesson, we will look at the most important of these functions: documentationdate.
With different parameters, the documentationdate function can return the current date / time in many different formats. Some of the most useful parameters are:
date("y")
Returns the current year from a date - with today's date, it returns: 14
date("m")
Returns the current month from a date - with today's date, it returns: 02
date("n")
Returns the current month from a date without leading zeroes ( eg. "1" instead of "01") - with today's date, it returns: 2
date("F")
Returns the current month name from a date - with today's date, it returns: February
date("d")
Returns the current day of the month from a date - with today's date, it returns: 08
date("l")
Returns the name of the current weekday from a date - with today's date, it returns: Saturday
date("w")
Returns the current day of the week from a date - with today's date, it returns: 6
date("H")
Returns the current hour from a time - with the current time, it returns: 07
date("i")
Returns the current minute from a time - with the current time, it returns: 11
date("s")
Returns the current second from a time - with the current time, it returns: 28
This example illustrates the use of the documentationdate function:
 <html>
 <head>
 <title>Time and date</title>

 </head>
 <body>

 <?php 
 
 echo "<p>Today it's " . date("l") . "</p>";

 ?>
 
 </body>
 </html>
 
 

The time is 1391839888

And now hold on... because now it becomes a little nerdy! The function documentationtime() returns the current time as the number of seconds since January 1, 1970, 12:00 PM, GMT.
 <html>
 <head>
 <title>time and date</title>
 </head>
 <body>

 <?php   

 echo "<p>It's been exactly " . time() . " seconds since January 1, 1970, 12:00 PM, GMT </ p> ";

 ?>

 </body>
 </html>
 
 
Time expressed in the number of seconds since January 1, 1970, 12:00 PM GMT is a so-called "timestamp" (UNIX timestamp) and is quite useful when you work with dates/times in the future or the past.
By default, the documentationdate function uses the current timestamp (i.e. the current value of documentationtime()). But with an extra parameter you can specify a different time stamp and thus work with the future or the past. In the example below, we set the timestamp to 0 seconds from January 1, 1970 12:00 PM, GMT. Thereby we can check what day of week January 1, 1970 was.
 <html>
 <head>
 <title>time and date</title>
 </head>
 <body>

 <?php 
 
 echo "<p>January 1, 1970 was a " . date("l",0) . "</p>";

 ?>

 </body>
 </html>
 
 
Unless you are a mathematical genius, it quickly becomes complicated to count the number of seconds since January 1, 1970 to a specific time in the future or past. But here you can get help from another nifty function: documentationmktime, which does the calculations for you.
The syntax for documentationmktime is (hour, minute, second, month, day, year). The example below converts the time of the first step on the Moon (July 21, 1969, 02:56):
 <html>
 <head>
 <title>time and date</title>
 </head>
 <body>

 <?php  
 
 echo mktime (2,56,0,7,21,1969);

 ?>

 </body>
 </html>
 
 
Notice that it's returning a negative number as the date is earlier than January 1, 1970.
We can now put this together with the documentationdate function and find out which weekday this historic day took place.
 <html>
 <head>
 <title>time and date</title>
 </head>
 <body>

 <?php
 
 echo date("l", mktime(2,56,0,7,21,1969));
 
 ?>
 
 </body>
 </html>
 
 

What can you use it for?

All this may seem a bit theoretical at this stage. After all, what on earth can you use a function like documentationtime() for? More importantly, when will you learn something you can actually use on your pages?
The answer is that what you learn here are building blocks - the only limitations to what you can build are your creativity and imagination! I would venture to say that you have already learned more than you think. For example, do you think you can make a website with different background images each day of the week and that works in all browsers?
Sure you can! Look at this example:
 <html>
 <head>
 <title>time and date</title>
 </head>

 <body background="background_<?php echo date("w"); ?>.png">

 </body>
 </html>
 

How to create PHP Scripts? Your first PHP page

From lesson 1 and 2, you now know a little about what PHP is, and you've installed (or have access to) a server. Now we are ready to begin making our first PHP page. We keep it simple and easy, but after you have gone through this lesson, you will understand much more about what PHP is and what you can do with it.
Basically, a PHP file is a text file with the extension .php which consists of:
  • Text
  • HTML tags
  • PHP Scripts
You already know what text and HTML tags are. So let's look a little more at PHP scripts.

PHP Scripts

PHP Documentation Group has issued detailed documentationdocumentation for PHP. Throughout the tutorial, there will be many links to the documentation. The goal is that you become accustomed to looking up and finding answers to your questions. PHP is so extensive that you can't to learn all facets in this tutorial. But PHP is not difficult! On the contrary, PHP is often very similar to plain English.
Let's get started with your first PHP page.

Example: Hello World!

Start by making an ordinary HTML document, but name the file page.php and save it in the root of the site:
  • If you use XAMPP  the path for the root is "c:\xampp\htdocs\page.php" on your computer (which is now a server).
  • If you have a website on a host that supports PHP, you simply upload/ftp the file to your web host.
The HTML code should look like this:
 <html>
 <head>
 <title>My first PHP page</title>

 </head>
 <body>

 </body>
 </html>

 
 
As you probably remember from lesson 1, PHP is all about writing commands to a server. So let's write a command to the server.
First, we need to tell the server when the PHP will start and end. In PHP you use the tags <?php and ?> to mark the start and end for the PHP codes that the server must execute (on most servers it will be suficient to use just <? as start tag, but <?php is the most correct to use the first time PHP is used.)
Now try to add the following simple code snippet to your HTML code:
 <html>
 <head>
 <title>My first PHP page</title>
 </head>
 <body>

 <?php   

 echo "<h1>Hello World!</h1>";

 ?>

 </body>
 </html>
 
 
When we look at the PHP document in a browser, it should look like this:
Illustration: Result in the browser
But it gets interesting when you look at the HTML code in the browser (by selecting "view source"):
Illustration: Viewing code
The PHP codes are gone! As you may remember from lesson 1, it is only the server that can see the PHP codes - the client (the browser) only sees the result!
Let's look at what happened. We asked the server to write <h1> Hello World!</h1>. In a more technical language, one would say that we used the string function documentationecho to write a specified string to the client where the semicolon ends the command. But do not worry! In this tutorial, we try to keep the technical language at a minimum.
Our first example is obviously not particularly exciting. But just wait! From now on, it's only going to be more and more interesting. Let's look at another example.

Example: Now!

Let's make the server write something else. We could, for example, ask it to write the current date and time:
 <html>
 <head>
 <title>My first PHP page</title>

 </head>
 <body>

 <?php   

 echo date("r");

 ?>

 </body>
 </html>
 
 
That will look like this in the browser:
Illustration: Result in the browser
And the corresponding HTML code:
Illustration: Viewing code
Now things are getting interesting, right?
We make the server write the date and time when the PHP page is displayed. Note that if you refresh the page in the browser, a new time is written. The server writes the current date and time each time the page is sent to a client.
It is also important to note that the HTML code contains only the date - not the PHP codes. Therefore, the example is not affected by which browser is used. Actually, all functionalities that are made with server-side technologies always work in all browsers!
And again, notice the semicolon after the code line. It is a separator and very important to include - otherwise the script won't work.
In the example, we used documentationdate, which is a function that returns the current date and time on the server.
Let's try to extend the example by writing both a string and a function - separated by "." (a period) - it's done like this:
 <html>
 <head>
 <title>My first PHP document</title>
 </head>
 <body>

 <?php 
 
 echo "<p>Current date and time: " . date("r") . "</p>";

 ?>

 </body>
 </html>
 
 
It will look like this in the browser:
Illustration: Result in the browser
And the corresponding HTML code:
Illustration: Viewing code

How to Install PHP on your computer?

PHP is a server-side technology. Therefore, you need to have a server to run PHP. But it doesn't need to cost you anything to make this upgrade and there are several options for doing so.
Since you ultimately only need to choose one option, this lesson is divided into three parts. First comes a little introduction on the different options (just choose the one that suits you best). When your server is up and running, we'll pick up with Lesson 3 to make your first PHP page.

Option 1: Website on a hosted server

You can choose to have a website on a host that supports PHP.
  • Test whether your host supports PHP
  • If you don't already have a website on hosted server you can create a free account on 000webhost.com which supports PHP.

Option 2: Install PHP on your computer

It's no walk in the park to install PHP on your computer. This option is only recommend for experienced computer users, but it can obviously be done. Here are links to downloads and installtion guides:

Option 3: XAMPP

XAMPP is a program that makes it easy and possible for us ordinary folks to run the PHP directly on our computer without having to install PHP on our own.

What is PHP? How does PHP work?

It is precisely these questions we will look at in this lesson. It's a big help to understand such basics related to PHP before you start developing you own PHP pages. Such basic understanding will increase the speed of learning significantly.
So, let's get started!

What is PHP?

PHP was originally an acronym for Personal Home Pages, but is now a recursive acronym for PHP: Hypertext Preprocessor.
PHP was originally developed by the Danish Greenlander Rasmus Lerdorf, and was subsequently developed as open source. PHP is not a proper web standard - but an open-source technology. PHP is neither real programming language - but PHP lets you use so-called scripting in your documents.
To describe what a PHP page is, you could say that it is a file with the extension .php that contains a combination of HTML tags and scripts that run on a web server.

How does PHP work?

The best way to explain how PHP works is by comparing it with standard HTML. Imagine you type the address of an HTML document (e.g.http://www.mysite.com/page.htm) in the address line of the browser. This way you request an HTML page. It could be illustrated like this:
The figure shows a client that requests an HTML file from a server
As you can see, the server simply sends an HTML file to the client. But if you instead type http://www.mysite.com/page.php - and thus request anPHP page - the server is put to work:
The figure shows a client that requests a PHP file from a server
The server first reads the PHP file carefully to see if there are any tasks that need to be executed. Only when the server has done what it is supposed to do, the result is then sent to the client. It is important to understand that the client only sees the result of the server's work, not the actual instructions.
This means that if you click "view source" on a PHP page, you do not see the PHP codes - only basic HTML tags. Therefore, you cannot see how a PHP page is made by using "view source". You have to learn PHP in other ways, for example, by reading this tutorial.
What you learn in this tutorial is to write commands to a server!
So, the first thing you need to get ahold of is... a server! But don't worry - you don't need to buy a new computer. You just need to install some software on your computer that makes it function as a server. Another option is to have a website on a hosted server that supports PHP. Then you just need to be online while coding.

HTML Marquee Code free tutorial


You can create a scrolling marquee (i.e. scrolling text or scrolling images) by using the <marquee> tag. You can make the text/images scroll from right to left, left to right, top to bottom, or bottom to top - it's your choice!
Note that if you can't view the examples, it's likely that your browser doesn't support the marquee tag.

Slide-in text:

This text slides in from the right, then stays where it is. You will need to refresh this page to see the effect again.
CODE
<marquee behavior="slide" direction="left">Your slide-in text goes here</marquee>

Continuous scrolling text:

CODE
<marquee behavior="scroll" direction="left">Your scrolling text goes here</marquee> 

Text bouncing back and forth:

CODE
<marquee behavior="alternate">Your bouncing text goes here</marquee> 

Text Scrolling Upwards:

CODE

<marquee behavior="scroll" direction="left" scrollamount="1">Slow scroll speed</marquee>

<marquee behavior="scroll" direction="left" scrollamount="10">Medium scroll speed</marquee>

<marquee behavior="scroll" direction="left" scrollamount="20">Fast scroll speed</marquee>



Scrolling Images:

CODE
<marquee behavior="scroll" direction="left"><img src="/pix/smile.gif" width="100" height="100" alt="smile" /></marquee>


Images & Text (Both Scrolling):

CODE
<marquee behavior="scroll" direction="left">
<img src="/pix/smile.gif" width="100" height="100" alt="smile" />
<p>Sample text under a <a href="/html/codes/scrolling_images.cfm">scrolling image</a>.</p>
</marquee>