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 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化