I've two tables let's say booking
and supplier
Fetching the records from both tables with-in date-range as follow
$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";
Note: I remove lots of code lines as they are not relevant to this question so as $WHERE1
and $WHERE2
, they are just date range clause.
After query fetching data (while loop) to HTML table
<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>
In HTML view, I know that <?php echo $row['RefNo'];?>
in href
belongs to which table booking
Or supplier
but PHP doesn't know it and on delete.php
I've to call both tables and first have to check the RefNo
against each table and then if it's true
delete the record
delete.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"
The question, is there better approach to delete the record where I don't have to call both tables and first check RefNo
against each table.
Edit to make Question more clear:
As I mentioned somewhere above that PHP doesn't know <?php echo $row['RefNo'];?>
belongs to which table booking
or supplier
so I need the work around where before any action (Delete, Cancel, Edit) I can tell PHP that <?php echo $row['RefNo'];?>
belongs to this table booking
or supplier
so no need to check <?php echo $row['RefNo'];?>
against both tables before any action Delete, Cancel, Edit