我是PHP和MySQL的新手,我正在尝试创建事件的主详细信息页面。母版页包含数据库中的所有事件以及简要说明,详细信息页面根据EventID提供有关该特定事件的更多信息。
PHP代码运行正常,并在详细信息页面中显示基于该事件的所有正确信息。但是从谷歌添加了一个地图链接,我想从该地址列获取该特定事件的值,并在地图上显示该位置。我知道在iframe中输入代码的位置,但我很难保存任何将地址值转换为变量。
我将链接以下代码。任何建议或帮助将不胜感激(就像我说我是这一切的新手,所以请好!):)
母版页
include"connect-mysql.php";
$sql = "SELECT * FROM Events";
$result = mysqli_query($conn,$sql);
?>
<html>
<body>
<?php
while($row=mysqli_fetch_assoc($result))
{
echo "<br><br>Event name: " .$row["EventName"],
"<br>Second Name: " .$row["EventDate"],
"<br><a href=googleDetail.php?EventID=" .$row["EventID"]. ">Details</a>";
}
?>
</body>
</html>
详细信息页面
include"connect-mysql.php";
$ID = $_GET["EventID"];
$Add1 = $_GET["EventAddress1"];
$Add2 = $_GET["EventAddress2"];
$Add3 = $_GET["Postcode"];
$sql = "SELECT * FROM Events WHERE EventID = '$ID' ";
$result = mysqli_query($conn,$sql);
?>
<html>
<body>
<?php
while($row=mysqli_fetch_assoc($result))
{
echo "<br><br>Event Name: " .$row["EventName"],
"<br>Event Date: " .$row["EventDate"],
"<br>Address 1: " .$row["EventAddress1"],
"<br>Address 2: " .$row["EventAddress2"],
"<br>Postcode: " .$row["EventPostcode"];
}
?>
<iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d2393.598194202707!2d-1.2525729846387041!3d53.1353580799353!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x4879967b2e53227b%3A0xf3a89e4d74b3556b!2sADDRESS GOES HERE!5e0!3m2!1sen!2suk!4v1487765096800" width="450" height="450" frameborder="0" style="border:0" allowfullscreen></iframe>
答案 0 :(得分:1)
尝试以下希望这有帮助。
<?php
$sql = "SELECT * FROM Events WHERE EventID = '$ID' ";
$result = mysqli_query($conn,$sql);
$row=mysqli_fetch_assoc($result);
?>
<iframe width="640" height="480" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.it/maps?q=<?php echo $row['EventAddress1']; ?>&output=embed"></iframe>