Hi I need some help please. I have records 280,000 or more in table “locations”, I am having trouble with my nested while loop,It takes more than 3 minutes to query the record to my database.and my ajax request is still showing loading icon in the firebug.in Net tab.
I know using native mysql is not good because it will be removed in the future ,but it takes time for me to recode the whole project ,I need to get this fix first before I will migrate to PDO.
Thank you in advance.
Here is the Php code.
position.php
<?php
include_once 'includes/dbconfig.php';
session_start();
$today = date('Y-m-d H:i:s');
$loginid = $_SESSION['loginid'];
$query_ = mysql_query("Select * from user_devices where user_id = '$loginid'")or die("problem in query = ".mysql_error());
$numrow_ = mysql_num_rows($query_);
if ($numrow_ > 0) {
while ($row_ = mysql_fetch_array($query_,MYSQL_BOTH)) {
$query = mysql_query("select ud.*,dt.*,dl.device_id as 'deviceid' ,dl.*,rfinfo.*
from user_devices ud left join mst_device_types dt
on ud.device_type = dt.id
inner join locations dl
on ud.device_id = dl.device_id
left outer join rfidinfo rfinfo
on dl.device_id =rfinfo.device_id
where dl.device_id = '$row_[2]' AND ud.user_id='$loginid'
order by dl.id desc LIMIT 1
")or die("problem in query = ".mysql_error());
while($row=mysql_fetch_array($query,MYSQL_BOTH)){
$coord[]= trim($row['latitude']).','.trim($row['longitude']);
.....
....
....
...
..
..
}
}
}
$return_data=array('coord'=>$coord,
....
....
...
...
...
...
...
....
);
echo json_encode($return_data);
?>
Here is my jquery.ajax that calls my Php script every 1 sec.
$(function(){
myinterval = setInterval(function(){
$.ajax({
type: "get",
dataType:'json',
url: "position.php",
success: function(data){
//perform some operation
}
}
});
},1000);
});