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 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分