Sunday, September 9, 2012

AJAX Database table Display


AJAX Database table Display  


Other web application transmit information to and from the sever using synchronous requests. This means you fill out a form, hit submit, and get directed to a new page with new information from the server.With AJAX when submit is pressed, JavaScript will make a request to the server, interpret the results and update the current screen.  the user would never know that anything was even transmitted to the server.
For the purpose of this tutorial,I have created database called "oops" and then created  the following table name "user".


CREATE TABLE IF NOT EXISTS `user` (
  `id` int(30) NOT NULL AUTO_INCREMENT,
  `FirstName` varchar(50) NOT NULL,
  `Surname` varchar(50) NOT NULL,
  `Age` varchar(50) NOT NULL,
  `Country` varchar(50) NOT NULL,
  `Job` varchar(50) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

--
-- Dumping data for table `user`
--

INSERT INTO `user` (`id`, `FirstName`, `Surname`, `Age`, `Country`, `Job`) VALUES
(1, 'Oksana', 'Babiak', '22', 'Ukrane', 'Web Developer'),
(2, 'Larisa', 'Volk', '30', 'Ukrane', 'Web Designer'),
(3, 'Ruth', 'Allen', '39', 'USA', 'Teacher'),
(4, 'Lissa', 'Diction', '31', 'Australia', 'Programmer');

Next create the HTML file which contains AJAX code

<html>
<head>
<script type="text/javascript">
function showUser(str)
{
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","user.php?id="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>

<center><form>
<select name="users" onchange="showUser(this.value)">
<option value="">Select a person:</option>
<option value="1">Oksana Babiak</option>
<option value="2">Larisa Volk</option>
<option value="3">Ruth Allen</option>
<option value="4">Lizza Dicton</option>
</select>
</form>
<br />
<div id="txtHint"><b>Person details will be listed here.</b></div></center>

</body>
</html>

Next create user.php which take data from MySQL table "user".

<?php
$id=$_GET["id"];

$con = mysql_connect('localhost', 'root', '');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("oops", $con);

$sql="SELECT * FROM user WHERE id = '".$id."'";

$result = mysql_query($sql);

echo "<table bgcolor=#b2bdaf>
<tr bgcolor=#ffffff>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
<th>Hometown</th>
<th>Job</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr bgcolor=#ffffff>";
  echo "<td>" . $row['FirstName'] . "</td>";
  echo "<td>" . $row['Surname'] . "</td>";
  echo "<td>" . $row['Age'] . "</td>";
  echo "<td>" . $row['Country'] . "</td>";
  echo "<td>" . $row['Job'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

mysql_close($con);
?>

Above codes will be created following smooth application


Person details will be listed here.
Firstname Lastname Age Hometown Job
OksanaBabiak22UkraneWeb Developer

Saturday, September 8, 2012

AJAX Change Text


AJAX Change Text 

AJAX is Asynchronous JavaScript and XML.If you have basic knowledge in Java Scripts and XML is enough for this lesson series. AJAX allows web pages to be updated by exchanging small amounts of data with the servers that it is possible to update parts of a web page, without reloading the whole page.
Importance of AJAX learning:-There are some instances like search auto suggestion we can not do without AJAX along with PHP JS or XML.Example of AJAX usage are Google Maps, Gmail, Youtube, and Facebook tabs.
I am not going to teach you all aspect of AJAX but i will try to present you most important usage example of AJAX
First Create following text file



Then create Following AJAX Script and save file in your root as html file and find the result

<!DOCTYPE html>
<html>
<head>
<script>
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","text.txt",true);
xmlhttp.send();
}
</script>
</head>
<body>

<div id="myDiv"><h2>AJAX change this text Click The Button Bellow</h2></div>
<button type="button" onclick="loadXMLDoc()">Change Content</button>

</body>
</html>


Tuesday, August 14, 2012

Interesting Emails

Interesting Emails I have got collection of Emails,received from my friends.Those which have different taste and also interesting.


  •  Secretary

GEORGE: Your new secretary is very sexy...
BILL: Thanks! She's actually a robot, named Monica ... If you squeeze her right breast, she takes dictation & if you squeeze her left breast, she types letters. Will work as long as you like, no complaining, no sick days, no medical, no dental......
I'll lend her to you for a day & you can see how functional and efficient she is.
Next day, George called Bill from the hospital & shouted:
 Bill… You bastard! You didn't tell me that the hole between Monica's legs is a Pencil Sharpener...
  •  Inside the wave... 
This photographer is from Oahu , Hawaii and he is gaining international fame.
He's a surfer himself and often gets wiped out just getting the shot, and you can see why!
These incredible images of waves were taken by the Number one photographer of surfs Clark Little.
He has dedicated his life to photographing the waves and has published a selection of the best images of his career.
He captures magical moments inside the "tube", as surfers say.
Sun...
Glints off wave

 
Sand...
In surf

 
Tubular... Shining
 
Beach...
Surf crashes down

 
Molten...
Liquid gold

 
White...
Tumultuous water

 
Splash...
Stunning shot

 
Red...
Mysterious shot

 
Break...
Wave crashes down

 
What a
Magical Wave!
  •  Women ...........!!!

Women are the best vehicles in the world because:
2 beautiful headlights in front
2 great bumpers at the back
Self lubricating when hot
Finger-touch ignition
Automatic engine oil change every month
Any type of pistons fit
Multiple seating styles & adjustments
Great accessories
Higest mileage: 9 months with just 5ml refill


 
That's why MEN die to get a ride ...! ! 
 During a visit to the mental hospital, I asked the Director 'How do
you determine whether or not a patient should be admitted to the
hospital.'



'Well,' said the Director, 'we fill up a bathtub, then we give a
teaspoon, a teacup and a bucket
to the patient and ask him to empty the
bathtub.'



'Oh, I understand,' I said. 'A normal person would use the bucket
because it's bigger than the spoon or the teacup.'



'No.' said the Director, 'A normal person would pull the drain plug.
Well....... Do you want a bed near the window?' 


  • Goat

chimpanzee

chimpanzee 

This is also a Email i received
Two years ago, at a Russian Zoo, a chimpanzee died leaving her baby orphaned. When one of the zoo employees took the baby home to care for it she never imagined that her Mastiff would adopt him and treat him as one of her puppies. Check out the photos below.




Saturday, July 28, 2012

Painted Hands



PAINTED HANDS 

Email Collection

It takes this guy four hours to do a hand.
Then he photographs it for posterity.
I cannot imagine how he does the eyes so remarkably lifelike.
It took him 10 hours to do the two-handed Eagle in picture #2.