gpt4 book ai didi

php - 处理两个不同的表时如何从表中删除记录

转载 作者:行者123 更新时间:2023-11-29 12:01:23 24 4
gpt4 key购买 nike

我有两个表,比如说 bookingsupplier

从两个表中获取日期范围内的记录,如下

$query = "SELECT booking.book_id AS Id,
booking.referance_no AS RefNo,
booking.entry_date AS DepDate,
booking.name AS Name,
booking.mobile AS mobile,
booking.comp_title AS Company
FROM booking WHERE active='1' $WHERE1
GROUP BY booking.book_id
UNION ALL
SELECT supplier.id AS Id,
supplier.reference_no AS RefNo,
supplier.departure_date_time AS DepDate,
supplier.name AS Name,
supplier.mobile AS Mobile,
supplier.company AS Company
FROM supplier WHERE active='1' $WHERE2
ORDER BY `DepDate` DESC LIMIT 1000";

注意:我删除了很多代码行,因为它们与这个问题无关,例如 $WHERE1$WHERE2 ,它们只是日期范围子句。

查询后将数据(while 循环)提取到 HTML 表

<td><?php echo $row['RefNo'];?></td>
<td><?php echo $row['Name'];?></td>
<td><?php echo $row['Mobile'];?></td>
<td><?php echo $row['DepDate'];?></td>
<td><?php echo $row['Company'];?></td>
<td><a class="btn" href="delete.php?RefNo=<?php echo $row['RefNo'];?>">Delete</a></td>

在 HTML View 中,我知道 <?php echo $row['RefNo'];?>href booking属于哪个表或supplier但 PHP 不知道,并且在 delete.php 上我必须调用这两个表,并且首先必须检查 RefNo针对每个表,然后如果它是 true删除记录

删除.php

 $ReferenceNo = $_GET['RefNo'];

//Fetch records from both tables
//Check records against `$ReferenceNo`
//If true against `booking` table
"Delete From booking where referance_no=$ReferenceNo"
//else
"Delete From supplier where reference_no=$ReferenceNo"

问题是,是否有更好的方法来删除记录,我不必调用两个表并首先检查 RefNo针对每个表。

编辑以使问题更清楚:

正如我在上面提到的,PHP 不知道 <?php echo $row['RefNo'];?> booking属于哪个表或supplier所以我需要在任何操作(删除、取消、编辑)之前解决问题,我可以告诉 PHP <?php echo $row['RefNo'];?>属于此表bookingsupplier所以不需要检查<?php echo $row['RefNo'];?>在执行任何操作之前针对两个表 Delete, Cancel, Edit

最佳答案

html 表格中的每一行都有如下内容:

<input type="hidden" name="myIncrNNN" value="tableX">

这是不可见的,它会提示您在处理时要做什么。

编辑:使其更清晰

你的

<td><a class="btn" href="delete.php?RefNo=<?php echo $row['RefNo'];?>">Delete</a></td>

将进行更改以拾取隐藏的列线索。

您现在将最终呼吁:

http://example.com/somedir/delete.php?RefNo=7

在我想象的世界里它会变成

http://example.com/somedir/delete.php?RefNo=7&tc=1

其中 tc 表示来自隐藏输入字段的表格线索

不需要更改架构,并添加表,并且很明显客户端正在告诉服务器要做什么,面对这一切,与原始的一样多或少,并且没有说客户端是一个任何事物的权威,就像@Halcyon 所暗示的那样。

编辑 2:(显示 UNION chg)

$query = "SELECT booking.book_id AS Id,
booking.referance_no AS RefNo,
booking.entry_date AS DepDate,
booking.name AS Name,
booking.mobile AS mobile,
booking.comp_title AS Company,
'booking' as TableClue -- <------ RIGHT THERE
FROM booking WHERE active='1' $WHERE1
GROUP BY booking.book_id
UNION ALL
SELECT supplier.id AS Id,
supplier.reference_no AS RefNo,
supplier.departure_date_time AS DepDate,
supplier.name AS Name,
supplier.mobile AS Mobile,
supplier.company AS Company,
'supplier' as TableClue -- <------ RIGHT THERE
FROM supplier WHERE active='1' $WHERE2
ORDER BY `DepDate` DESC LIMIT 1000";

关于php - 处理两个不同的表时如何从表中删除记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32311595/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com