0

我在 OpenLayers 上有一个热图应用程序,用户在其中输入两个日期和时间间隔,然后选择他/她是要查看这两个日期时间之间的所有数据还是根据每小时/每天/每周/每月间隔查看它们。但是,当我输入两个日期和时间作为输入并尝试可视化数据时,我只能可视化这两个间隔之间的所有数据。每当我从 HTML 下拉菜单中选择每小时、每天、每周等并按下获取查询按钮时,我都会收到 Ajax POST 消息中的错误消息。这可能是什么原因?代码如下:

HTML 帖子部分:

$(document).ready(function(){

 // ajaxForm submission
 $('#ajaxForm').submit(function() {
  $.ajax({
   type: 'POST',
   url: 'heatQuery.php',
   //url: 'http://localhost/heatQuery.php',
   data: $(this).serialize(),
   dataType: 'json',
   success: function(response)
   {   
       // update the points for heatmap layer          
       updateHeatMap(response);

   },
   error: function(errorMsg)
   {
       alert('Error in Ajax POST');
       }


  });

  return false;
 });
});

PHP部分:

setupDB.php

<?php

$mysql_hostname = "localhost";
$mysql_user = "myuser";
$mysql_password = "mypassword";
$mysql_database = "mydatabase";
$bd = mysql_connect($mysql_hostname, $mysql_user) or die("Oops some thing went wrong");
    mysql_select_db($mysql_database, $bd) or die("Oops some thing went wrong");

?>

热查询.php

<?php
include 'setupDB.php';
$coords_array = array();

function getPoints($dateTimeBeg,$dateTimeEnd)
{
$ses_sql= "SELECT lat,lon FROM `mytable` WHERE calltime >= '$dateTimeBeg' AND calltime <= '$dateTimeEnd'";  
    $result = mysql_query($ses_sql,$bd) or die('Error: ' . mysql_error());
    if($result)
    {
        $num_of_rows = mysql_num_rows($result);
        if($num_of_rows > 0)
        {
            while($row = mysql_fetch_row($result))
            { 
                array_push($coords,array($row[0],$row[1]));     
            }
            array_push($coords_array,$coords);
        }
    }
}

$hours = array(1 => '00:00', '01:00', '02:00', '03:00', '04:00', '05:00', '06:00', '07:00', '08:00', '09:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00', '17:00', '18:00', '19:00', '20:00', '21:00', '22:00', '23:00', '24:00');

$dateBeg = isset($_POST['date1']) ? $_POST['date1'] : "";
$dateEnd = isset($_POST['date2']) ? $_POST['date2'] : "";
$dateFreq = isset($_POST['freq']) ? $_POST['freq'] : "";

if($dateBeg && $dateEnd && $dateFreq) // if all variables are set
{
    $datetime1 = new DateTime($dateBeg);
    $datetime2 = new DateTime($dateEnd);
    $interval = $datetime1->diff($datetime2,true);

    if($dateFreq == "all")
    {
        $coords = array();
        $timeBeg = $_POST['time1'];
        $timeEnd = $_POST['time2'];
        $sp = " ";
        $dateTimeBeg = $dateBeg.$sp.$timeBeg;
        $dateTimeEnd = $dateEnd.$sp.$timeEnd;
        $ses_sql= "SELECT lat,lon FROM `mytable` WHERE calltime >= '$dateTimeBeg' AND calltime <= '$dateTimeEnd'";  
    $result = mysql_query($ses_sql,$bd) or die('Error: ' . mysql_error());
    if($result)
    {
        $num_of_rows = mysql_num_rows($result);
        if($num_of_rows > 0)
        {
            while($row = mysql_fetch_row($result))
            { 
                array_push($coords,array($row[0],$row[1]));     
            }
            array_push($coords_array,$coords);
        }
    }

    }else if($dateFreq == "hourly")
    {       
        for($i=1;$i<=24;$i+=1)
        {
            $coords = array();
            $timeBeg = $hours[$i];
            $timeEnd = $hours[$i+1];
            $dateTimeBeg = $dateBeg.$sp.$timeBeg;
            $dateTimeEnd = $dateBeg.$sp.$timeEnd;
            $ses_sql= "SELECT lat,lon FROM `mytable` WHERE calltime >= '$dateTimeBeg' AND calltime <= '$dateTimeEnd'";  
    $result = mysql_query($ses_sql,$bd) or die('Error: ' . mysql_error());
    if($result)
    {
        $num_of_rows = mysql_num_rows($result);
        if($num_of_rows > 0)
        {
            while($row = mysql_fetch_row($result))
            { 
                array_push($coords,array($row[0],$row[1]));     
            }
            array_push($coords_array,$coords);
        }
    }

        }
    }else if($dateFreq == "daily")
    {
        for($i=1;$i<=interval;$i+=1)
        {
            $ses_sql= "SELECT lat,lon FROM `mytable` WHERE calltime >= '$dateTimeBeg' AND calltime <= '$dateTimeEnd'";  
    $result = mysql_query($ses_sql,$bd) or die('Error: ' . mysql_error());
    if($result)
    {
        $num_of_rows = mysql_num_rows($result);
        if($num_of_rows > 0)
        {
            while($row = mysql_fetch_row($result))
            { 
                array_push($coords,array($row[0],$row[1]));     
            }
            array_push($coords_array,$coords);
        }
    }
        }
    }

    $coords_json = json_encode($coords_array);
    echo $coords_json;

//echo $coords;

    mysql_close($bd);
}

?>

编辑:

根据 bPratik 的请求,我还放置了 HTML 代码的替代发布错误,其中包括我从服务器获得的错误:

error: function(jqXHR, textStatus, errorThrown)
   {

       alert('Error in Ajax POST\ntextStatus: ' + textStatus + '\nerrorThrown: ' + errorThrown);
    }

尽管如此,我只收到 AJAX Post 消息中的错误消息。奇怪的是,mysqld.exe 进程运行了一段时间——显然它实际上同时检索了查询——然后我得到了消息。

4

1 回答 1

0

前段时间解决了这个问题,稍后会发布详细信息。

于 2012-09-11T23:40:45.217 回答