Make money without investing even a single penny. visit the our sponser's web site to learn about making money online. create your own blog with google and place google adds .. come here to learn php & mysql..
Search This Blog
Saturday, August 1, 2009
Make Connections to Mysql Database
අද මට හිතුනා සිංහලෙන් ලියන්න කියලා. අපි අද ඉඳලා බලන්න හදන්නේ, කොහොමද mysql දත්ත ගබඩාවක අපිට ඕනෑ කරන ආකාරයට දත්ත සකසන්නේ කියලා. ඒ ඔක්කෝටම කලින් අපි අද බලමු mysql දත්ත ගබඩාවකට වෙබ් පිටුවක ඉඳලා
Thursday, July 16, 2009
How to write Switch Case statement in PHP
Here we can today learn how we could write a switch case construct in php. You know this statement we called it as conditional structure. that means this switch is used to do something if conditions provided are satisfied. this is basically equal to the if - else if - else statement.
here is the syntax for the Switch statment;
switch($var)
{
case "1":
echo"it is one";
break;
case "2":
echo"it is Two";
break;
case "3":
echo"it is Three";
break;
default:
echo "defaul Value ";
break;
}
Tuesday, May 5, 2009
Loop constructs in PHP
Firs sorry for waiting long time to post this since my last post. I was having lot of works to complete in last few days. herewith today we gonna look at loops in php
as in other languages php has loop/iterative construct. those loop construct are
- for
- while
- do .. while
- foreach
for loop ..
for($i=0; $i < 10; $i++)
{
echo ($i . '< br />');
}
//----------------------------------------------
While Loop
while($row=mysql_fetch_array($result))
{
echo ($row[0] . "< br />");
}
//----------------------------------------------
Do While loop
$i=0;
do
{
$i++;
echo ("the no is:" . $i . "< br />");
}
while($i<5);
//------------------------------------------------
foreach loop
$persons= array("name"=>"mcDonald","city"=>"torento","country"=>"USA");
foreach($item=keys($persons ))
{
echo($persons[ $item] . "< br />");
}
we will try the case statement in next lesson and i'll stop @ here thanks gys n galls
Thursday, April 16, 2009
arrays in PHP
To day We will look @ arrays in php
in PHP we can find two types of arrays that one is array that we usually used
with numeric indexed, and another one is associative arrays. this type of arrays
also behave as same as usuall arays we used to.. only difference is we can use alphanumeric key index.
You can understand this with following example..
normally array is key value paired .
ex1:
[0] => 456
[1] => 3456
[2] => 566
[3] => 70
-------------------------------------------
ex 2:
["name"] => "Mc.Donald"
["ID"] => 1234567889
["SSN"] => "239898K"
["Country"] => "Australia"
["age"] => 45
in first example array index keys are numeric values {0,1,2,3} but in example 2 it is an alphanumeric values {name,ID,SSN,Country,age}
How can create and access the arrays in PHP
arrays can be created and accessed in normall way how we do in other languages only difference is we dont specify the type of the values that holds by the array
see below example how we create array.
$Marks= array(0=>12,1=>34,2=>50,3=>60,4=>45); this array definition is also same as below definition..
$MarksII= array(12,34,50,60,45); // with this style index is autogenerated.
echo $Marks[0]; // output is 12
echo $MarksII[0]; // output is 12
now we see ho we can create an associative array ..
this is also same as normal array definition.
$StudentsMarks = array("kamal"=>30,"amal"=>34,"nimal"=>50,"sunil"=>20); // this holds an marks of each stdents for a particular subject
how we can print marks of a given student.
echo $StudentsMarks["amal"]; /// this wil echoes the marks of student amal. output is 34
echo $StudentsMarks["sunil"]; /// this wil echoes the marks of student sunil. output is 20
when we working with array we have to loop through the array. how we can loop associative array
is like this...
foreach($key=key($StudentsMarks))
{
echo "marks of $key : $StudentsMarks[$key]<>";
}
this will prints an out put like below...
marks of kamal : 30
marks of amal : 34
marks of nimal : 50
marks of sunil :20
i think you got some idea about arrays in PHP and im retain @ here.. we'll meet again with onother lesson
thank you..
Saturday, April 4, 2009
PHP lesson II
Today we gonna have a look at data types and variable in PHP
is there any data type in php? have you ever noticed that? like other programming languages we don't mention the data type of the variable wehen it declares huh..?
ex..
in C# ig we want an integer variable we declare it like this
int i=0;
but with PHP we dont mention it so. what we do is we simply use
$i=0;
why we can do this, how php going to identify the type of the variable then.. does php has no data type ? we have to find answers fo these questions rite?
the reason for this defference is "typing" what is typing means.. while other laguages use "strong type" php is gonna use "weekly type". basically in a higher level PHP has scalar type only. but behid the screen you can find couple of data type those are integer,string,double. PHP identifies the data type depending on the variable context.. you can see this with the following simple script
$i=10; // this will be integer type
$f=250.00; //this is a double
$str="Hi i'm string"; // this is string type
$s='im too string '; // This is also a string
$c='a'; // This is also a string
/*to see the data type of each variable we can use getType(); function*/
echo( getType($i));
echo "<br/>"; ;
echo(getType($f));
echo "<br/>";
echo( getType($str));
echo "<br/>"; ;
echo( getType($s));
echo "<br/>"; ;
echo(getType($c));
echo "<br/>";
?>
The out put will be like this
integer
double
string
string
string
try this.. hope you got to know something new..
will meet with another lesson later
bye...
:-)
Friday, April 3, 2009
හිංගලෙන් ලියන්න හිතුනා
එහෙනම් මම මෙතනින් නවතිනවා.. බොහෝම ස්තූතියි.
Thursday, March 5, 2009
PHP: Simple hello world script
here we going to write some simple PHP scripts to see how we can deveop a web page using PHP.
first of all , there should be a web Server installed in your computer so that we can browse for our web page. It is better if you have apache server installed or else one of the server bundle from XAMP [this has for both windows and linux ],WAMP [for windows users],LAMP [linux users].
if you are a windows user and already you have IIS installed then donload PHP binaries from www.php.net wich is official web site for PHP and install it in your computer ..
After these step now we can sart development of our web pages with PHP. later appliations we can go to dance scripts even with db connections and web services, xml ,sockets, pdf, etc.. we may need some additional libraries to do programming in rlated to above mentioned things.. any way later with my applications im going to use mySql as my database serer. it is also a open source and free to download the free version and its better if u can download it and insatall it n your computer.
seem that is enough for basic hre will star our web tutorial..
first open up a text editor on your computer. we dont need any spacial IDE to do this exaple.. its really enough to have a saml text editor tool.
the php scripts realy starts with <?php tag and it is end with ?>. actually what ever the php conent is gone within this tag. other wise it is not executed by the php engin/web server .
see complete sample php file to our example.
mytest1.php
---------------
<html>
<head>
<title>PHP: Our sample Hello world application</tittle>
</head>
<body>
<?php
echo "Hello : You are wel come to my web site";
// we are done, our first example
?>
</body>
</html>
This is one of the way that we can print string into the response web page. ther is onether way we an do this that is without including html tags. any way i dont recomend that way to use web pages except for the class files written in php.
i.e :
<?php
echo "Hello : You are wel come to my web site";
// we are done, our first example
?>
ok, now we go to explanation above example.
echo(); is the function that prints any out put to the page.
you can see that the out put is enclosed within the double quatation marks " " this tells the server that this is the string which should be print onto the response. there is one of other way to do this. that is using the single quotation mark
' ' see the following example.
i.e
<?php
echo
' hello : You are wel come to my web site';
// we are done, our first example
?<
why there is two ways of doing this ? what is the difference between these two? guess..? actually it has difference. when you use single quot '' to echo something echo will print all the string same as it is appears to our eye. there is no limitation of escape character sequenes or som eother else.
but if you are using double quot "" then the out put is change.. say you have some escape character within the double quat then echo will for sure escape those character and print he output..
will learn those in next tutorial..
here lm gonna take a shower
thank you.
semiolon ( ; ) is the operator we used to tell that this is the end of the line.