Computers

Basics of a server side scripting language : PHP (part 2)

Haven’t read part 1 yet? Go to PART 1 else you’re good to continue!
In this tutorial we’ll be learning how to echo out an image, much advanced calculations using variables, using the IF statement and using arrays.

Ready? Good! Lets start working.


Echoing out an image
Nothing to worry here. It’s simple; a small change to make from how you would normally write.
<?php
echo “<img src=’the-location-of-your-image’ width=’100′ length=’100′ />”;
?>


Much advanced calculations using variables
<?php
// { plus is + | minus is – | multiplication is * | division is / }

$num1 = 10;
$num2 = 2;

echo $num1 / $num2 equals .$num1 / $num2
//you need to use a period in an echo function to do more than one thing

echo $num1 + $num2 divided by $num2 is equal to .($num1 + $num2) / $num2;
//what we want to happen is add $num1 and $num2 and divide its answer by $num2
//if brackets are not used it will divide $num2 by $num2 and add $num1 to its answer

//you can change everything accordingly and try it out with any other symbol
?>


Using the IF statement
Lets try a very basic condition first.
<?php
//== means is equal to. You use = only with variables
if (1==1)
{echo
True;
}
else
{echo
False;
}

//obviously 1 is equal to 1 xD
?>

<?php
//if you need to create a simple log-in system
$username=tutebox;
$password=
abc;
if ($username && $password)
{echo
Access granted!;
}
else
{echo
Access denied!;
}

//You need yo use text boxes and there’s a lot more modification required to do a nice system.
?>


Using Arrays
Arrays allow you to store more than one piece of data inside a variable. And this can be done in another way or two also; what you’ll be learning is the most neatest, easiest and it’s professional.
<?php
$days = array(
Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday);
echo
Today is . $days[2]; //a much neater way | or else
echo Today is $days[2];
//first array is 0, second is 1, third is 2 etc..
?>

– thanks for your comments

Share this post

Related Posts

6 thoughts on “Basics of a server side scripting language : PHP (part 2)”

  1. Dewayne Murra says:

    PHP PHP PHP………. THANKS ALOT!

  2. Pingback: script man
  3. smokeless cigarettes says:

    This is among the most incredible blogs Ive read in a incredibly prolonged time. The level of data in here is breathtaking, like you practically wrote the book on the subject. Your blog is excellent for anyone who wants to realize this topic a lot more. Excellent things; please keep it up!

  4. Pingback: used industrial machinery
  5. ruzeen says:

    Fine; inclusive of proper reference. Peace.

  6. Samson says:

    I would like to thank you for the time you put into this post. Your post has me eager to begin my own site now. Thanks again for taking the time to put this online.

Comments are closed.