我有这张卡车表。
<div class="myform">
<form id="form" name="form" method="post" action="">
<table border="1">
<tr>
<th>Plate Number</th>
</tr>
<?php do { ?>
<tr>
<td><?php echo strtoupper($row_Trucks['truck_plate_no']); ?></td>
</tr>
<?php } while ($row_Trucks = mysql_fetch_assoc($Trucks)); ?>
</table>
</form>
</div>
此卡车列表与交货详细信息表相关
tbl_delivery_details, tbl_po, tbl_waybill, tbl_fuel_details, tbl_driver...
并且还连接到数据库中的一堆其他表。当我单击表格上的卡车车牌号并将我链接到另一个页面时,如何显示与每辆卡车相关的记录,该页面将显示与该卡车相关的所有记录,卡车表是另一个页面的外键表。
最佳答案
尝试这样的事情。
如果truck_plate_number
是唯一的,您可以将其与链接一起传递,如下所示。否则,获取记录的ID(主键)并将$truck_plate_no
替换为该ID在下面的代码中。
<div class="myform">
<form id="form" name="form" method="post" action="">
<table border="1">
<tr>
<th>Plate Number</th>
</tr>
<?php do {
$truck_plate_no=$row_Trucks['truck_plate_no'];
echo '<tr><td><a href=anotherpage.php?truck_plate_no='.$truck_plate_no.'>'.strtoupper($truck_plate_no).'</td></tr>';
} while ($row_Trucks = mysql_fetch_assoc($Trucks));
?>
</table>
在 anotherpage.php
<?php
$truck_plate_number=$_GET['truck_plate_no'];//get value from url
?>
然后使用这个id从表中查询详细信息。
关于php - 在新页面上显示外键记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20436811/