tutebox.com

Computers

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

July 10, 2010 by Ruzeen Rezvie in PHP, Programming with 6 Comments

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

Tagged , ,

Recommend this post

Related Posts

6 Comments

  1. Dewayne MurraJuly 11, 2010 at 1:49 pmReply

    PHP PHP PHP………. THANKS ALOT!

  2. script manJuly 13, 2010 at 8:07 pmReply

    Basic stuff?? these sounds very advance to me ;-)

  3. smokeless cigarettesJuly 15, 2010 at 6:05 amReply

    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. used industrial machineryJuly 15, 2010 at 12:52 pmReply

    A Good Read…

    Very helpful info thanks…

  5. ruzeenAugust 14, 2010 at 6:28 amReplyAuthor

    Fine; inclusive of proper reference. Peace.

  6. SamsonJanuary 16, 2011 at 10:30 amReply

    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.

Leave a reply

Your email address will not be published. Required fields are marked *

*

Stay Connected