Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/387.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.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
PHP和Javascript,两者的工作代码组合无法显示_Javascript_Php - Fatal编程技术网

PHP和Javascript,两者的工作代码组合无法显示

PHP和Javascript,两者的工作代码组合无法显示,javascript,php,Javascript,Php,我有两个工作代码。这第一个有点复杂,但它让我回到了我需要的位置 <?php $ider = $_GET['id']; $host = "localhost"; $user = "Meh"; $password ="pass"; $database = "MyDB"; mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); // connect to mysq

我有两个工作代码。这第一个有点复杂,但它让我回到了我需要的位置

    <?php

    $ider = $_GET['id'];

    $host = "localhost";
    $user = "Meh";
    $password ="pass";
    $database = "MyDB";

    mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

    // connect to mysql database
    try{
        $connect = mysqli_connect($host, $user, $password, $database);
    } catch (mysqli_sql_exception $ex) {
        echo 'Error';

    }
    $sql = "SELECT id, Location FROM MyDB WHERE id =$ider";
    $result = $connect->query($sql);

    if ($result->num_rows > 0) {
        // output data of each row
        while($row = $result->fetch_assoc()) {
            $thisloc = $row["Location"];
        }
    } else {
        echo "0 results";
    }
    $conn->close();
    ?>

现在我想在带有多个标记的lil google api javascript boyo上使用这些信息

<html>
  <head>
    <title>Custom Markers</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <style>
      /* Always set the map height explicitly to define the size of the div
       * element that contains the map. */
      #map {
        height: 100%;
      }
      /* Optional: Makes the sample page fill the window. */
      html, body {
        height: 90%;
        width: 70%
        margin: 0;
        padding: 0;
      }
    </style>
  </head>
  <body>
    <div id="map"></div>
    <script>

      var map;
      function initMap() {
        map = new google.maps.Map(
            document.getElementById('map'),
            {center: new google.maps.LatLng(62.009094, -7.316163), zoom: 13});

        var iconBase =
            'https://developers.google.com/maps/documentation/javascript/examples/full/images/';
        var iconBase2 =
              'http://icons.iconarchive.com/icons/paomedia/small-n-flat/32/';

        var icons = {
          equipment: {
            icon: 'http://icons.iconarchive.com/icons/icons-land/vista-map-markers/32/Map-Marker-Marker-Outside-Azure-icon.png'
          },
          library: {
            icon: iconBase2 + 'map-marker-icon.png'
          },
          info: {
            icon: iconBase + 'info-i_maps.png'
          }
        };

        var dormant = 'equipment';
        var active = 'library';
        var later = 62.013376;
        var longer = -7.307036;

        var features = [
          {
            position: new google.maps.LatLng(62.018596, -7.292223),
            type: dormant
          }, {
            position: new google.maps.LatLng(62.013376, -7.307036),
            type: dormant
          }, {
            position: new google.maps.LatLng(62.009094, -7.316163),
            type: dormant
          }, {
            position: new google.maps.LatLng(62.990540, -7.318134),
            type: dormant
          }, {
            position: new google.maps.LatLng(62.005287, -7.309028),
            type: dormant
          }, {
            position: new google.maps.LatLng(later, longer),
            type: active
          }

        ];

        // Create markers.
        for (var i = 0; i < features.length; i++) {
          var marker = new google.maps.Marker({
            position: features[i].position,
            icon: icons[features[i].type].icon,
            map: map
          });
        };
      }
    </script>
    <script async defer
    src="https://maps.googleapis.com/maps/api/js?key=mykey&callback=initMap"> >
    </script>
  </body>
</html>

自定义标记
/*始终明确设置贴图高度以定义div的大小
*包含映射的元素*/
#地图{
身高:100%;
}
/*可选:使示例页面填充窗口*/
html,正文{
身高:90%;
宽度:70%
保证金:0;
填充:0;
}
var映射;
函数initMap(){
map=新建google.maps.map(
document.getElementById('map'),
{中心:新google.maps.LatLng(62.009094,-7.316163),缩放:13});
var iconBase=
'https://developers.google.com/maps/documentation/javascript/examples/full/images/';
var iconBase2=
'http://icons.iconarchive.com/icons/paomedia/small-n-flat/32/';
变量图标={
设备:{
图标:'http://icons.iconarchive.com/icons/icons-land/vista-map-markers/32/Map-Marker-Marker-Outside-Azure-icon.png'
},
图书馆:{
图标:iconBase2+“地图标记图标.png”
},
信息:{
图标:iconBase+“info-i_maps.png”
}
};
var休眠=‘设备’;
var active='库';
var later=62.013376;
var更长=-7.307036;
变量特征=[
{
位置:新google.maps.LatLng(62.018596,-7.292223),
类型:休眠
}, {
位置:新google.maps.LatLng(62.013376,-7.307036),
类型:休眠
}, {
位置:新google.maps.LatLng(62.009094,-7.316163),
类型:休眠
}, {
位置:新google.maps.LatLng(62.990540,-7.318134),
类型:休眠
}, {
位置:新google.maps.LatLng(62.005287,-7.309028),
类型:休眠
}, {
位置:新google.maps.LatLng(稍后,更长),
类型:活动
}
];
//创建标记。
对于(变量i=0;i
正如你所看到的,我不是一个非常老练的程序员。更像是垃圾场的狗。 有很多事情在那里进行,但是我正处于一些变化的中间,我需要测试的信息。
这两个脚本似乎无法协同工作,无法显示页面。我这样做对吗?任何建议都很好

如果数据库具有地名而不是协调,请尝试改用此API

https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=<?php echo$thisloc;?>&inputtype=textquery&fields=photos,formatted_address,name,geometry&key=YOUR_API_KEY
https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=&inputtype=textquery&fields=photos,格式化的\地址、名称、几何图形和键=您的\ API \键

在听取@Rkv88-Kanyan的建议并进行了一天的故障排除后,我成功地隔离了问题。实际上是PHP。奇怪的是,当我回显一个结果时,它会显示输出,但由于没有回显,所以无法显示页面

无论如何 我只是把PHP脚本重写成我所需要的。这可能不是世界上最复杂的事情。但我每次只需要一个特定的值

<?php

$ider = $_GET['id'];

        $conn = mysqli_connect("localhost", "meh", "pass", "MyDB"); 
        // Check connection
        if ($conn->connect_error) {
            die("Connection failed: " . $conn->connect_error);
            }

        $sql = "SELECT Location FROM LifeSaver1 WHERE id =$ider";
        $result = $conn->query($sql);
        $obj = mysqli_fetch_object($result);
        $obj2 = $obj->Location;

?>


您可能希望首先将JS放在自己的文件中,并使用带有
src=“yourfile.JS”
的脚本加载它,这样您就可以在JS上运行JS验证,在HTML上运行HTML验证。现在,你的HTML中至少有一个流氓
。还要修复SQL查询,因为它有潜在的SQL注入攻击。对不起,我在键附近看到了它。HTML和javascript验证。。。这对我来说是新的…加载你说的javascript,就像你使用Css一样?@Mike‘Pomax’KamermansI并不太关心Rkv88 Kanyan-Kanyan的安全性。这只是一个项目演示。半小时内完成。我还需要修复它吗?如果只是学习演示,那么就不需要了