duanbi6522 2019-05-07 17:43
浏览 53
已采纳

如何通过单击发送数据并运行包含该数据的链接

I want to send latitude and longitude data so I can search it up on Google Map. Those data has to be selected from a database but I can't figure how to do it in one click.

Here is my code.

<?php 
$con = mysqli_connect("localhost","root","","project"); 
// Check connection 
if (mysqli_connect_errno()) 
{ 
    echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
}

$result = mysqli_query($con,"SELECT * FROM table1");

echo "<table border='1'> 
    <tr> 
    <th>ID</th> 
    <th>Latitude</th> 
    <th>Longitude</th> 
    <th>Date</th>
    </tr>";

while($row = mysqli_fetch_array($result)) 
{ 
    echo "<tr>"; 
    echo "<td>" . $row['id'] . "</td>"; 
    echo "<td>" . $row['latitude'] . "</td>"; 
    echo "<td>" . $row['longitude'] . "</td>"; 
    echo "<td>" . $row['date'] . "</td>"; 
    echo "<td><a href='./clicktest.php?id=".$row['id']."'>View Location</a></td>"; 
    echo "</tr>"; 
} 
echo "</table>";

mysqli_close($con); 
?>

And as you can see, it sends the id value of a row that I want to another page which is

<?php 
$con=mysqli_connect("localhost","root","","project"); 
if (mysqli_connect_errno()) 
{ 
    echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
}

if(isset($_GET['id'])) {
    $result = "SELECT * FROM table1 WHERE id='".$_GET['id']."'" ;
    $show = mysqli_query($con, $result);
    while($row = mysqli_fetch_array($show)) 
    {
        $latitude = $row['latitude'];
        $longitude = $row['longitude'];
        echo "<a href='http://www.google.com/maps/place/".$latitude.",".$longitude."'>click here</a>";  
    } 
    mysqli_close($con);     
}
?>

And finally can run a link to Google Map on this page. But what I want is to click on the 'view location' on the first page and jump to the google map page with data on that row without having to go through another page and another click.

I did some research and maybe this is about AJAX? And are there any ways to do it without using AJAX?(since I never use it before)

Thanks

  • 写回答

2条回答 默认 最新

  • dongrong5189 2019-05-07 18:03
    关注

    I think you need to directly link to google maps page and use "target=_blank" attribute on it. for example:

    echo '<a href="http://www.google.com/maps/place/' . $row['latitude'] . ',' . $row['longitude'] . '" target="_blank">View Location</a>';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP