Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaScript和PHP代码中的问题_Javascript_Php_Json - Fatal编程技术网

JavaScript和PHP代码中的问题

JavaScript和PHP代码中的问题,javascript,php,json,Javascript,Php,Json,我有一个我不明白的问题 这是我的JavaScript文件,存在于js目录中(代码的一部分): 这是我的get_data_google_api.php文件,位于(inc)目录中(代码的一部分) 我不知道为什么用select*from records(records是包含所有信息的表)测试它。我没有在http://localhost/innotech/inc/get_data_google_api.php因此地图将为空 但当我使用例如从id=6784或id=6786或id=6788或id=6782的

我有一个我不明白的问题

这是我的JavaScript文件,存在于js目录中(代码的一部分):

这是我的get_data_google_api.php文件,位于(inc)目录中(代码的一部分)

我不知道为什么用
select*from records
records
是包含所有信息的表)测试它。我没有在
http://localhost/innotech/inc/get_data_google_api.php
因此地图将为空

但当我使用例如
从id=6784或id=6786或id=6788或id=6782的记录中选择*进行测试时,它会在
中显示这些idhttp://localhost/innotech/inc/get_data_google_api.php
以及地图中(仅那些id,而不是所有数据)


我想知道为什么
select*from records
不起作用。

也许您的表中有任何错误数据。我试着复制并测试你的代码,一切正常。把数据填到表格里,然后再多说几句

另一个技巧是,是否关闭javascript函数末尾的右括号和父项

HTML


为什么要返回每个标记的所有记录。。。为什么不直接返回该标记的记录(假设标记和记录之间存在某种关系)-或者,一次获取所有记录。。。在javascipt中做一些调整,以获得每个标记的正确记录(尽管,我知道你在获取所有记录方面有问题),请阅读-总结是,这不是一种理想的方法来解决志愿者问题,并且可能对获得答案产生反作用。请不要把这个添加到你的问题中。只有当你告诉他他的代码是正确的时,也许他的数据会出错。一个变化:javascript get函数的右括号和parentesis足够公平了
    // This function will iterate over markersData array
    // creating markers with createMarker function
    function displayMarkers(){

   // this variable sets the map bounds according to markers position
   var bounds = new google.maps.LatLngBounds();

   // for loop traverses markersData array calling createMarker function for 
     each marker 
     $.get("http://localhost/innotech/inc/get_data_google_api.php", 
     function(response) { 
       markersData = JSON.parse(response);
      //console.log(response);
    header('Access-Control-Allow-Origin: *');

    $servername = "localhost";
    $username = "root";
    $password = "123456";
    $dbname = "rythmstu_innotec";
     // Create connection
      $conn = new mysqli($servername, $username, $password, $dbname);
     // Check connection
     if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
    }

     $return_arr = Array();

     $sql ="select * from records";
     $result = $conn->query($sql);

     while ($row = $result->fetch_assoc()) {
     array_push($return_arr,$row);
      }

      echo json_encode($return_arr);
$.get("./test.php", 
        function(response) { 
            markersData = JSON.parse(response);
            console.log(markersData);
        }
    );