I modified the code here (http://www.w3schools.com/PHP/php_ajax_database.asp) to update and display my database after an input box is typed and a button is clicked to submit.
I have
<form method="post" action="process.php" id="processer" onsubmit="showUser('me');">
<label for="Process">Process</label><input type="text" name="process" id="process">
<input type="submit" value="Process">
</form>
My Ajax code sends a:
xmlhttp.open("GET","getuser.php?q="+str+"&t=" + Math.random(),true);
xmlhttp.send();
and finally my getuser.php is
<?php
$q=$_GET["q"];
$con = mysql_connect('localhost', 'root', '');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("short", $con);
$sql="SELECT * FROM table WHERE creator = '$q'";
$result = mysql_query($sql);
echo "<table border='1'>
<tr>
<th>id</th>
<th>data</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>
<td>" . $row['id'] . "</td>
<td>" . $row['data'] . "</td>
</tr>";
}
echo "</table>";
mysql_close($con);
?>
The problem is that when I click submit, sometimes 1 refreshes, sometimes 2 refresh, and others none at all. Like let’s say i’m submitting the numbers 1 through 10, first time through I see 1, 2, then after inputting 3, i dont see anything, then suddenly 3, 4, and then nothing then 5 (while I just inputted 6), then 6, then 7, 8.
Is my php display data getting cached? or how can i make the refreshing smooth and consistent?
Thanks in advance.
Try indexing your database so you get faster response times..