How a database is loaded into an application?
Posted
by Audel
on Stack Overflow
See other posts from Stack Overflow
or by Audel
Published on 2010-04-17T17:25:39Z
Indexed on
2010/04/17
17:33 UTC
Read the original article
Hit count: 246
Hi
All i need is a simple explanation on how does this function work
I also attached a piece of php which I think is the one that retrieves the data from the database. Please correct me if I'm wrong
Cheers.
function loadDatabaseRecords ()
{
// Mozilla/Safari
if (window.XMLHttpRequest)
{
xmlHttpReq = new XMLHttpRequest();
}
// IE
else if (window.ActiveXObject)
{
xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}
alert ("To Server (Load Records):\n\najax-open-DB.php");
xmlHttpReq.open('GET', "ajax-open-DB.php", true);
xmlHttpReq.onreadystatechange = loadDatabaseRecordsCallback;
xmlHttpReq.send(null);
}
<?php
$link = mysql_connect ("ipaddress", "localhost", "password");
mysql_select_db ("database1");
$query = "SELECT * from addressbook";
$result = mysql_query ($query);
print "<table>";
print "<tr>";
print "<th>Firstname</th><th>Lastname</th><th>Address</th><th>Telephone</th>";
print "</tr>";
for ($i = 0; $i < mysql_num_rows ($result); $i ++)
{
$row = mysql_fetch_object ($result);
print "<tr>";
print "<td>$row->firstname</td>";
print "<td>$row->lastname</td>";
print "<td>$row->address</td>";
print "<td>$row->telephone</td>";
print "</tr>";
}
print "</table>";
mysql_close ($link);
?>
© Stack Overflow or respective owner