我有一个我正在研究的内部网站,它的第一部分从数据库返回一个查询,并在交付路径上提供停止。下一步需要将这些结果转换为链接,因此现在路由上的每个停靠点都是一个链接。我希望每个路由都有一个与其名称相等的值。因此,如果第1行返回结果“Hospital”,那么当我点击该链接时,它将把“Hospital”的值带到下一页。
这是我到目前为止所做的,我尝试了几种不同的方法,例如在链接的值中添加一个echo以显示变量,但没有任何效果。
<?php
$route_name=$_GET['route_name'];
$day=$_GET['day'];
$database=$_GET['database'];
$inches=$_GET['inches'];
$data="snow_removal" . $database;
/*use this line for localhost*/ $con=mysqli_connect("localhost","root","pass","DB");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$query = " SELECT customer
FROM $data
WHERE route_name=$route_name
AND inches<=$inches
AND $day
;";
$result = mysqli_query($con,$query);
echo "<table border='1'><tr><th>Customers</th>
</tr>";
while($row = mysqli_fetch_assoc($result))
{
echo "<tr>";
echo "<td> <a href='snow.php'> " . $row['customer'] . "</a></td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
任何推动正确方向的想法都将受到高度赞赏。
由于
答案 0 :(得分:0)
看起来这部分HTML存在问题:
<a href='snow.php'> " . $row['customer'] . "</a>
将GET请求用作HREF:snow.php?customer=x
您可以通过GET请求传递值(此处可能是客户名称)。
传递的数据将显示在$_GET
超全球中。
(第一个参数附加到包含?param=value
的网址。
使用¶m2=value
将以下参数附加到该参数。
这使您可以使用多对:page.php?param=value¶m2=value
。)
我建议更改此行
echo "<td> <a href='snow.php'>".$row['customer']."</a></td>";
进入这个:
echo "<td> <a href='snow.php?customer=".$row['customer']."'>".$row['customer']."</a></td>";
而且......因为看起来很糟糕,让我们提取URL结构。
因此,我们最终得到以下两行:
$url = 'snow.php?customer=' . $row['customer'];
echo "<td> <a href='".$url."'>".$row['customer']."</a></td>";
您也可以手动调用此URL:snow.php?customer=hospital
(或任何其他客户,如果您知道名称)。
然后在snow.php
页面上,处理进入$_GET['customer']