Hi, I am trying to use AJAX to pull back mysql table information. I tried to alter an example I found (w3 schools) where they showed how use a selection table to pull a specific line out of a mysql table, using the "q" (not really sure if the "q" character is important or not) .... (xmlhttp.open("GET","xxxxxxx.php?q="+str,true);) I follow what they were doing there, but I want to pull the entire table back not just specific lines. (So I got rid of the Q)
Here is a snipit of HTML. The showdata function is part of the testpull.js code. You click the button and it should run the javascript to pull back the entire table and place it in the "placedata" div section.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>xxxxxxxxx</title>
<link type="text/css" rel="stylesheet" href="sig.css" />
<script type="text/javascript" src="testpull.js"></script>
</head>
<body>
...................
<div id="getdata">
</div><br />
<button type="button" onclick="showdata()">showdata</button>
<div id="placedata">
</div>
</div>
Here is my javascript file ..........
function showdata()
{
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("placedata").innerHTML=xmlhttp.responseText;
}
xmlhttp.open("GET","getalldata.php",true);
xmlhttp.send();
}
}
Here is my PHP "getalldata.php" file........ let assume there are three fields in each row of the table but I only want column 2 & 3...
<?php
$con = mysql_connect('xxxxx', 'xxxxxx', 'xxxxxx');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("xxxxxxxxx", $con);
$sql="SELECT * FROM table_list
$result = mysql_query($sql);
echo "<table border='1'>
<tr>
<th>field2</th>
<th>field3</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['field2'] . "</td>";
echo "<td>" . $row['field3'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
If anyone could help me with this I would greatly appreciate it.