php - 在新页面上显示外键记录

标签 php html mysql sql

我有这张卡车表。

<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/

相关文章:

php - PHP 'and' 运算符的奇怪行为

html - 应用显示 :table to the parent 时,子宽度设置为相等且不能更改

html - 当我扩展 base.html/for django 时,是否可以排除 base.html 中包含的 footer.html

mysql - 按计数和另一个标准抓取行 MySQL

mysql - 停止左连接中的数据重复

php - 使用 PHP post 函数时遇到奇怪的问题

php - 如何使用 PHP/MYSQL 在单个查询中执行 SELECT 和 INSERT?

php - CakePHP - HABTM 分页查询问题

javascript - 动态 HTML 元素中的多个 JSON 或 JavaScript 对象

mysql - 将两个表合并为一个并删除重复项