reading php-mysql data through xmlhttprequest

F

foraci

Dear group,
I have tried for the whole week to get the following done. But all I
face is failure. My task is to fetch data from mysql through php and
display the fetched row in javascript with xmlhttprequest object
without using xml. Directly using the open function with GET and POST.
What I get is all the data are displayed. But I want to process
each of mysql in the javascript with the help of xmlhttprequest object.
Is it possible or I am going in a wrong direction. Any help is
appreciated. Since I am a beginner I could not able to do more. If this
is not the group then pls direct me.

Following is the code:

The .html file: (I did not chk for IE and onreadystatechange)
---------------
<html>
<head>

<script language="javascript">

var xmlhttp, tmp;

function start() {
var row_0,row_2,row_1;
xmlhttp = new XMLHttpRequest();

xmlhttp.open("GET",'noxml.php',false);
xmlhttp.send(null);
tmp=xmlhttp.responseText;

var mybody = document.getElementsByTagName("body")[0];
mytable = document.createElement("table");
mytablebody = document.createElement("tbody");

for(var j = 0; j < 3; ++j)
{
mycurrent_row = document.createElement("tr");
for(var i = 0; i < 3 ; ++i)
{

mycurrent_cell = document.createElement("td");

currenttext = document.createTextNode(tmp) ;

mycurrent_cell.appendChild(currenttext);
mycurrent_row.appendChild(mycurrent_cell);
}
mytablebody.appendChild(mycurrent_row);
}
mytable.appendChild(mytablebody);
mybody.appendChild(mytable);
mytable.setAttribute("border","2");
}



</script>
</head>

<body onLoad="start()">

</body>

</html>

The .php file:
-------------

<?php
$user = "sathya";
$passwd = "sathya";
$dbname = "ajax";
$conn = mysql_connect("localhost",$user,$passwd);
global $row_0 ,$row_1,$row_2;
if(!$conn)
die("error in mysql connection".mysql_error());
$db = mysql_select_db($dbname);
$quere = "select * from product";
$countris = mysql_query($quere);
if(!$db)
die("error in mysql db".mysql_error());
if(!$countris)
die("error table".mysql_error());

while($row = mysql_fetch_row($countris))
{

$row_0 = $row[0];
$row_1 = $row[1];
$row_2 = $row[2];

$_POST['row_0'] = $row_0;
$_POST['row_1'] = $row_1;
$_POST['row_2'] = $row_2;

echo $row_0.' ', $row_1.' ', $row_2.'<br>';
}


?>

The .sql has 3 col

Thanks for any help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top