Multiple selection boxes to search a database - php

I've changed the code with the selection boxes to the below:
<html>
<head>
<script type="text/javascript">
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.frm.modelSelection.innerHTML=xmlhttp.responseText;
}
}
var makevalue=document.frm.makeSelection.value;
xmlhttp.open("GET","http://www.autodeal.co.za/newsite/model-selection?ajaxmake="+‌​makevalue,true);
xmlhttp.send();
}
</script>
</head>
<body>
<?php
$dbName = "F:/Domains/autodeal/autodeal.co.za/wwwroot/newsite/db/savvyautoweb.mdb";
// Throws an error if the database cannot be found
if (!file_exists($dbName)) {
die("Could not find database file.");
}
// Connects to the database
// Assumes there is no username or password
$conn = odbc_connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=$dbName", '', '');
?>
<form action="index.php?option=com_content&view=article&id=99" method="post" name="frm">
<select name="makeSelection" onchange="loadXMLDoc()">
<?php
//Loads the Makes from the database into a dropdown
$resultMake = odbc_exec($conn, "SELECT DISTINCT Make FROM Vehicle ORDER BY Make") or die (odbc_errormsg());
while ($rowMake = odbc_fetch_array($resultMake)) {
echo "<option value='$rowMake[Make]'>$rowMake[Make]</option>";
}
?>
</select><br />
<select name="modelSelection">
</select><br />
<select name="yearSelection">
<option>2004</option>
<option>2005</option>
<option>2006</option>
<option>2007</option>
<option>2008</option>
<option>2009</option>
<option>2010</option>
<option>2011</option>
<option>2012</option>
<option>2013</option>
<option>2014</option>
</select><br />
<select name="priceSelection">
<option>< 5000</option>
<option>5000 - 20 000</option>
<option>20 000 - 50 000</option>
<option>50 000 - 100 000</option>
<option>100 000 - 200 000</option>
<option>200 000 - 300 000</option>
<option>300 000 - 400 000</option>
<option>400 000 - 500 000</option>
<option>50 000 - 1 000 000</option>
<option>> 1 000 000</option>
</select>
<input type="submit" name="submit" value="Go">
</form>
</body>
</html>
Hi,
I've updated the code to reflect the answers below, but now, when you make the first selection, the Model selection box remains empty.
modelSelection.php
<?php
$dbName = "F:/Domains/autodeal/autodeal.co.za/wwwroot/newsite/db/savvyautoweb.mdb";
// Throws an error if the database cannot be found
if (!file_exists($dbName)) {
die("Could not find database file.");
}
$conn = odbc_connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=$dbName", '', '');
//loads the models based on the makes selection into a dependant dropdown
if (isset($_REQUEST['ajaxmake'])) {
$resultModel = odbc_exec($conn, "SELECT Model FROM Vehicle WHERE Make = '".$_REQUEST['ajaxmake']."'") or die (odbc_errormsg());
while ($rowModel = odbc_fetch_array($resultModel)) {
echo "<option value='$rowModel[Model]'>$rowModel[Model]</option>";
die(); //I'm not sure where to put this because I assume this is the reason why this selection must be first
}
}
?>

As far as I can see, the problem is that you are loading the whole request response text inside a select button. I've looked at your request response and it is responding the whole page with the models loaded, so basically it is getting all options and loading them on the Model select box, because you are inserting the whole page on the model select box.
You have multiple options here:
You can create a page that only loads the Model options, so have a file which has only this part:
$dbName = "F:/Domains/autodeal/autodeal.co.za/wwwroot/newsite/db/savvyautoweb.mdb";
// Throws an error if the database cannot be found
if (!file_exists($dbName)) {
die("Could not find database file.");
}
$conn = odbc_connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=$dbName", '', '');
//loads the models based on the makes selection into a dependant dropdown
if (isset($_REQUEST['ajaxmake'])) {
$resultModel = odbc_exec($conn, "SELECT Model FROM Vehicle WHERE Make = '".$_REQUEST['ajaxmake']."'") or die (odbc_errormsg());
while ($rowModel = odbc_fetch_array($resultModel)) {
echo "<option value='$rowModel[Model]'>$rowModel[Model]</option>";
}
}
And change the page you are calling through ajax to point to that page:
xmlhttp.open("GET","newpage.php?ajaxmake="+ makevalue,true);
The other option, and the one I suggest you is to look into some javascript library, such as jQuery which has functions to easen your work.
If you include jQUery library, adding the select name as id="makeSelection" and id="modelSelection" you could write a javascript function like this:
jQuery(document).ready(function(){
jQuery("#makeSelection").change(function(){
jQuery("#modelSelection").load("?ajaxmake="+ makevalue + #modelSelection option");
});
});
BTW! Be aware that you may have a huge security problem in your sql queries, since people can attack you through the ajaxmake variable, and truncate/drop your tables or anything. I suggest you to sanitize and validate the data coming from your requests, specially if you post some sensitive data like your database tables on the internet!!! If you want to know more about SQL Injection (how this security issue is called): How can I prevent SQL injection in PHP?

I am not sure why you have html included in your ajax processing file. Usually you keep a .php file consisting only of php code and then you can be sure no html or script code are being included (which is currently happening in your page now).
For one, try to change your model dropdown code to:
<?php
//loads the models based on the makes selection into a dependant dropdown
if (isset($_REQUEST['ajaxmake'])) {
echo "<select name='modelSelection'>"; //select tag placed here
$resultModel = odbc_exec($conn, "SELECT Model FROM Vehicle WHERE Make = '".$_REQUEST['ajaxmake']."'") or die (odbc_errormsg());
while ($rowModel = odbc_fetch_array($resultModel)) {
echo "<option value='$rowModel[Model]'>$rowModel[Model]</option>";
}
echo "</select><br>";
die(); //<-- the die placed here will not execute the rest of
//the code and also all the options will be populated
}
?>

Related

jQuery data sent from PHP is not the correct format?

I am using jQuery to send a part number from one php file to another.
The part number is received correctly in the destination php file, but when when I try to use it, it does not work.
Here is the strange thing: To test,when I use $mpn=STA-12 (or any other value that exists in table2), in destination php file, the connection is established and the relevant data is extracted, BUT when THE SAME DATA is fetched, it does not work
Here is the destination PHP file:
<?php
$row['mpn'] = $_GET['q'];
include("order/connection.php");
echo "mpn is here : ".$row['mpn']; // It displays STA-12 but doesn't data get fetched!
$mpn=$row['mpn'];
//$mpn="STA-12"; // *** When I actually put this line in, it all works ***
$stmt = $pd->prepare("SELECT * FROM table2 WHERE part_number = :part_number " );
//$stmt->execute(array());
$stmt->execute(array(':part_number' => $mpn));
$row = $stmt->fetch(PDO::FETCH_BOTH);
//... rest of the code
?>
This jQuery script copied from W3:
<script>
function showUser(str) {
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
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 (this.readyState == 4 && this.status == 200) {
document.getElementById("txtHint").innerHTML = this.responseText;
}
};
xmlhttp.open("GET","serv.reply3.3.php?q="+str,true);
xmlhttp.send();
}
}
And this is where it is called from:
<form>
<select name="users" onchange="showUser(this.value)">
<option value="">Choose</option>
<option value=" <?php echo $row["mpn"]; ?> ">items</option>
</select>
</form>
The problem is finally solved.
Since the code was copied from another example, the jQuery variable sent over, contained some EXTRA information that when ECHO'ed didn't show.
echo "mpn is here : ".$row['mpn']; that displayed STA-12, actually contained ' string(6) " STA-12" ', which was discovered by doing:
var_dump( $row['mpn']).
This had my head scratching for days.

File upload input from AJAX retrieved file not being detected

I made a dynamically changing HTML form where I can change the type of input of the form between a file upload or a drop down box that is populated from a remote database. The function that calls which input type to be displayed is in AJAX. When I submit the form using the drop down box, the form submits without any problems and performs the update to the database that I programmed it to do. However, when I try to submit the form while trying to upload the file, my error checking script (which are simple if... statements) tells me that it BOTH doesn't detect any file being uploaded and the file already exists on the database. However, when the "already exists on database" error appears, it doesn't return the name of the file that I'm trying to upload like I programmed it to do, so I suspect that my file isn't being submitted properly.
Can someone tell me what I did wrong?
Here's the script I have so far:
File 1: test.php
<html>
<body>
<head>
<script>
function getInput(value)
{
var xmlhttp;
if (value=="")
{
document.getElementById("display").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("display").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","grabtest.php?q="+value,true);
xmlhttp.send();
}
</script>
<?php
// connect to database on server
$con=mysqli_connect("localhost","username","password","database name");
// if there was an error in connecting to the database, display the error
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
</head>
<form enctype="multipart/form-data" action="test2.php" method="POST">
<select id='SelectInput' onchange='getInput(this.value)'>
<option selected value=''>Select</option>
<option value='N'>New File</option>
<option value='E'>Existing File</option>
</select>
<div id="display"></div><br>
<input type="submit" value="Submit">
</form>
<?php
if (!empty($_POST)){
if ($_FILES["file"]["error"] == 0){
$target = 'PathName/TargetFolder/';
$target = $target . basename($FILES['file']['name']);
if (file_exists('PathName/TargetFolder/' . $_FILES["file"]["name"])){
echo $_FILES["file"]["name"] . " already exists on server. ";
}
else{
$upload = $_FILES["file"]["name"];
$select = mysqli_query($con, "Select Files from DB_Table where Files = '$upload'");
if (mysqli_num_rows($select) > 0){
echo $_FILES["file"]["name"] . " already exists in database. ";
}
else{
//script for moving the uploaded file to the proper storage location on the server and adding it to the database
move_uploaded_file($_FILES["file"]["tmp_name"], $target . $_FILES["file"]["name"]);
echo "Stored in: " . $target . $_FILES["file"]["name"] . "<br>";
$insert="INSERT INTO DB_Table (Files) VALUES ('$upload')";
if (!mysqli_query($con,$insert)){
die('Error: ' . mysqli_error($con));
}
echo "Your data has been added to the database";
}
}
if ($_POST['recipe']=="" and !file_exists($_FILES['file']['tmp_name']) and !is_uploaded_file($_FILES['file']['tmp_name'])){
exit("Please select or add the file.");
}
}
mysqli_close($con);
?>
File 2: grabtest.php
<?php
//connect to database on server
$con=mysqli_connect("localhost","username","password","database name");
//if there was an error in connecting to the database, display the error
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$q=$_GET["q"];
if ($q==""){
echo "";
}
elseif ($q=="N"){
echo "Select recipe to upload: <input type='file' name='newfile'>";
}
elseif ($q=="E"){
//creates a dropdown box where you can select desired field
$list = mysqli_query($con, "select * from DB_Table");
echo 'Files: <select name = "Files">';
while ($row = mysqli_fetch_array($list))
{
echo '<option value = "' . $row["ID"] . '">' . $row["Files"] . '</option>';
}
echo '</select><br>';
echo '</form>';
}
//after script is executed, close connection to database
//this improves security by ensuring the connection to the database does not remain open when there is no activity being done to change the data
mysqli_close($con);
?>

use one text field to search database, then pupulate remaining fields in PHP

I'm new here, so I hope this makes sense I am new to PHP and Ajax...so I am quite lost.
I have a MySQL database setup, and several forms created in PHP. I have several text fields on one of the forms, which is supposed to show customer info. The first text (phone #) field is supposed to be a search field ... so I need to query my database once the user finishes entering the phone #, to find the records and populate the remaining fields.
I've tried various ways of doing this...but nothing comes out quite right! The method which seems to show the most promise is by using the Onblur event to call a php page (using Ajax) which will perform the search.
This works, in that I can query the database to find the results .. and have them displayed back. The trouble is that this page with the data inside is actually displayed in the middle of my first page ...so basically I have one web page displaying inside the other...which is obviously not what I want.
The basic code I have is:
HTML side --
<script>
function showUser(str) {
if (str == "") {
document.getElementById("divider").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) {
document.getElementById("divider").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET", "GetCustomer.php?q="+str, true);
xmlhttp.send();
}
</script>
</head>
<label for="CustPhone">Phone:</label>
<input type="text" name="CustPhone" id="CustPhone" tabindex="1" onchange="showUser(this.value)" value="<?php ?>">
<br>
<div id="divider"></div>
<label for="CustLastName">Last Name:</label>
<input type="text" name="CustLastName" id="CustLastName" tabindex="2" value="<?php echo $clast; ?>">
<label for="CustFirstName">First Name:</label>
<input type="text" name="CustFirstName" id="CustFirstName" tabindex="3" value="<?php echo $cfirst; ?>">
<p> </p>
<label for="CustAddress1">Address 1:</label>
<input type="text" name="CustAddress1" id="CustAddress1" tabindex="4" value="<?php echo $caddr1; ?>">
<label for="CustAddress2">Address2:</label>
<input type="text" name="CustAddress2" id="CustAddress2" tabindex="5" value="<?php echo $caddr2; ?>">
<p> </p>
and the PHP --
include ("AddEdit.php");
require_once("customer_info.php");
function LoadData()
{
$pn = $_POST['CustPhone'];
if (strlen($Pn) < 10)
{
$query = "SELECT * FROM customer WHERE Phone='$Pn'";
$result = mysql_query($query);
if (!$result) die ("Database access failed: " . mysql_error());
$rows = mysql_num_rows($result);
$rowinfo = mysql_fetch_array($result);
if ($rows > 0)
{
$clast = $rowinfo['LastName'];
$cfirst = $rowinfo['FirstName'];
$caddr1 = $rowinfo['Address1'];
$caddr2 = $rowinfo['Address2'];
$ccity = $rowinfo['City'];
$cprov = $rowinfo['Province'];
$cpostal = $rowinfo['Postal'];
}
}
}
Any ideas as to how I can do this without jumping around as much ... or more importantly just show the data on the existing page, rather than showing a smaller version of my entire page within the page ??
Thx!!!
I will recommend to use Jquery Ajax, more simple and easy way for Ajax.
For more details, refer Jquery Ajax.
So you can change your Ajax call as follows :
$.ajax({
type: "POST",
url:"GetCustomer.php",
data: "q="+str,
success : function(data) {
//do someting with your data
}
}
});
With this you can handle error state as well as display "in progress" bar while the Ajax call is in progress.
In success you need to map your data with the fields in form instead of displaying them inside a div. This is the only thing you are missing in your approach. So instead of following line -
document.getElementById("divider").innerHTML = xmlhttp.responseText;
add JS code to map the data with the fields.
You can use JSON datatype and easily map the data with your forms.
First, I recommend to use jQuery ajax instead of old ajax.
I Think your result are not in the correct place because you are using "innerHTML" in this line of code
document.getElementById("divider").innerHTML = xmlhttp.responseText;
so your results will be there.

Why is this AJAX function not working properly?

I have written a simple application that displays a list of candidates for a job, then, upon clicking a hire button, should alter a database to reflect the newly hired candidate and display the rest as unhired. However, the function is not working properly. The problem I am having is the AJAX function never seems to provide a response, and I cannot figure out why. The database is also not getting updated. My files are below.
The line document.getElementById("errors").innerHTML+=xmlhttp.readyState+" "+xmlhttp.status+"<br>"; is updating a div at the bottom of my html page, showing that the the readyState is 4 and the status is 200, which should mean that the AJAX function returned properly, but the echo'd response is not being displayed. Even when I remove all code from the new_hire.php file and simply make the file echo "hello";, nothing is returned in the responseText.
resumes.php:
<html>
<head>
<script type="text/javascript">
function new_hire(name){
var xmlhttp;
if (window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
}
else{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function(){
document.getElementById("errors").innerHTML+=xmlhttp.readyState+" "+xmlhttp.status+"<br>";
//this line, when removed, does not change anything. I left it in for debugging purposes.
document.getElementById("errors").innerHTML+=xmlhttp.responseText;
if (xmlhttp.readyState=4 && xmlhttp.status=200){
var others = xmlhttp.responseText.split("|");
for (i=0;i<others.length;i++){
tag = others[i].replace(" ","_");
document.getElementById(tag).innerHTML="";
}
}
}
xmlhttp.open("POST","new_hire.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("hiree="+name.replace(" ","%20")+"&position=Salespeople");
var name_tag = name.replace(" ","_");
document.getElementById(name_tag).innerHTML="(Current Employee)<br>";
}
</script>
</head>
...
</html>
new_hire.php (AJAX response file):
<?php
$hiree = $_POST['hiree'];
$pos = $_POST['position'];
$con = mysql_connect("host.name","user","pass") or die('Could not connect: ' . mysql_error());
mysql_select_db("dbname",$con);
$clear = mysql_query("UPDATE $pos SET employed=false WHERE 1=1;");
mysql_fetch_array($clear);
$reset = mysql_query("UPDATE $pos SET employed=true WHERE Name='$hiree';");
mysql_fetch_array($reset);
$people = mysql_query("SELECT Name FROM $pos WHERE employed=false;");
$array = array();
while ($row = mysql_fetch_array($people)){
array_push($array,$row['Name']);
}
mysql_close($con);
$response = join("|",$array);
echo $response;
?>
Please note that your if statement is not using the comparison operator == but rather the assignment operator = so you are using: if (xmlhttp.readyState=4 && xmlhttp.status=200) instead of if (xmlhttp.readyState==4 && xmlhttp.status==200)

Ajax page does not update consistently

I've recently started exploring using AJAX for a small project, and I've had reasonable success though it's not as smooth as I would like.
The Basic setup is that an applications named ProphetX which interfaces with Excel to show stock market prices. Prices are updated as they change in Excel. Using VBA I save the data from the spreadsheet into an SQL08 DB every time a price updates. This could sometimes be a few times per second.
Using PHP on an Apache server I connect to the SQL DB and load the data into tables, and a javascript function to keep updating the information once every second. I've noticed however that at times the page will simply hang if you already have it up, or load a blank screen if you pull it up, particularly when data is being updated rapidly. So to the meat of my question: Is there something in my code which could be causing this hiccup? I doubt it is congesting the network or server resources as I've been monitoring them and they seem low.
Also I used WireShark to monitor network traffic, and when I load up the page and it shows blank in the browser, I can see the HTML being sent from the server to my machine.
Any help / coding style criticism is much appreciated, source code below.
Index.php:
<html>
<head>
<script type="text/javascript" src="update.js"></script>
</head>
<body onLoad = update()>
<font size = +2>
<?php
echo "
<div id = 'marketData'></div>
";
?>
</font>
</body></html>
Update.js:
function update()
{
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("marketData").innerHTML=xmlhttp.responseText;
}
}
//URL needs a var to be passed via get for code to function in IE, thus Math.Random().
//I am also confused by this requirement.
xmlhttp.open("GET","update.php?i="+ Math.random(),true);
xmlhttp.send();
var t = setTimeout("update()", 3000);
}
Update.php:
<?php
//connect to database
error_reporting(0);
sqlsrv_configure("WarningsReturnAsErrors", 1);
$server = "myServer";
$db = "myDB";
$connectionInfo = array("Database"=>"$db, "UID"=>"user", "PWD"=>"pass");
$conn = sqlsrv_connect($server, $connectionInfo);
if($conn)
{
echo "<font size =-1 color=green>Connection Established<br></font>";
}
else
{
echo"Connection not established:<br>";
print_r(sqlsrv_errors());
}
//Func calls sqlsrv_query($conn, [$symbol],[$DatabaseName])
$stmt = sqlsrv_query($conn,query(array('sym1','sym2','sym3'), "electronic") );
errorCheck($stmt);
printTables("Electronic Commodity Prices", $stmt);
$stmt = sqlsrv_query($conn,query(array('sym1','sym2','sym3'), "floor") );
errorCheck($stmt);
printTables("Floor Commodity Prices", $stmt);
$stmt = sqlsrv_query($conn,query(array('sym1','sym2','sym3',... ,sym19), "natgas") );
errorCheck($stmt);
printTables("Natural Gas Commodity Prices", $stmt);
sqlsrv_free_stmt($stmt);
sqlsrv_close( $conn);
//This function prints out the tables
function printTables($tableName, $stmt)
{
echo
"
$tableName<hr>
<table cellspacing ='5' cellpadding = '5'>
<tr>
<th>Symbol</th>
<th>Product</th>
<th>Last Price</th>
<th>Change</th>
<th>High Price</th>
<th>Low Price</th>
<th>Previous Price</th>
<th>Trade Time</th>
</tr>
";
while($row=sqlsrv_fetch_array($stmt))
{
echo
"
<tr>
<td>$row[symbol]</td>
<td><font size =+3 color = blue>$row[description]</font></td>
<td>$row[last]</td>
<td><font size =+5> $row[change]</font></td>
<td>$row[highPrice]</td>
<td>$row[lowPrice]</td>
<td>$row[previousprice]</td>
<td>" . date("j M g:i",strtotime($row['tradetime'])) . "</td>
</tr>
";
}
echo"</table><hr>";
}
function query($symbols, $db)
{
$count = count($symbols);
$stmt =
"
select distinct id,symbol,description,last,change,highPrice,lowPrice,previousprice,tradetime from $db
where ";
for($i = 0; $i< $count; $i++)
{
$stmt .= "id in (select MAX(id)from $db where symbol ='$symbols[$i]') ";
if($i != $count-1)
{
$stmt.= "or ";
}
}
$stmt .= "order by description asc";
// id in (select MAX(id)from $db where symbol ='$symbols[0]')
// or id in (select MAX(id)from $db where symbol ='$symbols[1]')
// or id in (select MAX(id)from $db where symbol ='$symbols[2]')
// order by description asc
return $stmt;
}
function errorCheck($stmt)
{
if( $stmt=== false )
{
echo "Error in statement preparation/execution.\n";
die( print_r( sqlsrv_errors(), true));
}
}
?>
Without running your code locally, I would suggest you look into DB locking issues. If you are really updating your DB records a number of times a second, and trying to load you query page ever three seconds (your timeout is set to 3000, which is three seconds). If your query page takes longer than three seconds to load because of DB locking issues then your browser may having blocking issues, as it is waiting for the response from one request while firing a new ajax request.
You could try putting some timeout code in your php query page.

Categories