我正在尝试从数据库中过滤一些数据(幅度和日期),以在地图上显示标记,因为出现的标记太多。
当我单击提交按钮时,我的地图没有出现。是什么原因造成的?
注意:当我尝试不进行过滤时,我的地图会正确显示所有标记。
这是我的代码:
<div class="main">
<form action="" method="post">
<h3> Past Earthquakes:</h3>
<br />
<p>Select Magnitude:
<input type="number" id="select_magnitude" name="select_magnitude" min="1.00" max="10.00" step="0.1" placeholder = "select magnitude" style="width:200px">
   
Select Date : <input type="date" id="earthquake-date" name="earthquake-date" placeholder = "">   
<input type="submit" name="search" value="search">
</p>
<div id="mapid"></div>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "Earthquake";
// Create connection
$conn = mysqli_connect("$servername", "$username", "$password", "$dbname");
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
if (isset($_POST['submit'])) {
$magnitude = $_POST['select_magnitude'];
//$date = $_POST['earthquake-date'];
$sql = "(SELECT * FROM tbl_earthquake where `Magnitude`= '".$magnitude."')";// AND `Date`='".$date."')";
$result = mysqli_query($conn, $sql);
echo "
<script type='text/javascript'>
var mymap = L.map('mapid').setView([-20.176907099999998,57.46742810000001], 3);
var marker;";
if (mysqli_num_rows($result)>0){
while($row = mysqli_fetch_assoc($result)){
echo "marker=L.marker([".$row['Latitude'].",".$row['Longitude']."]).addTo(mymap);";
//echo "marker=L.marker([-20.176907099999998,57.46742810000001]).addTo(mymap);";
}
}
echo"
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw', {maxZoom: 20,
attribution: 'Map data © <a href=https://www.openstreetmap.org/>OpenStreetMap</a> contributors, ' +
'<a href=https://creativecommons.org/licenses/by-sa/2.0/>CC-BY-SA</a>, ' +
'Imagery © <a href=https://www.mapbox.com/>Mapbox</a>',
id: 'mapbox.streets'
}).addTo(mymap);
</script>";
}
?>
</form>
</div>