[英]Delete * from two tables inner join
hello to all I have created in my project two tables that have the same id, the structure of the tables is this: 你好,我在我的项目中创建的两个具有相同ID的表,这些表的结构是这样的:
campagne: 康帕涅:
id_campagna
data_inizio
data_fine
and table campagne_cliente 和桌子campagne_cliente
id_campagna_cliente
cliente_id_campagna
impianto_id_campagna
my will is to delete all the data contained in the two tables when the id 我的意愿是删除ID为2的两个表中包含的所有数据
id_campagna
id_campagna_cliente
are the same. 是相同的。
also place the elimination procedure, from the table where they are shown all the data I have to select: id_campagna_cliente 还要从显示表格的地方放置消除程序,我必须选择所有数据:id_campagna_cliente
in this way: 通过这种方式:
<a href="#elimina<?php echo $row['id_campagna_cliente']; ?>" data-toggle="modal" class="btn-floating btn-sm btn-pin "><span class="glyphicon glyphicon-trash"></span> <i class='fa fa-remove' aria-hidden='true'></i></a>
this is the modal: 这是模态:
<div class="modal fade" id="elimina<?php echo $row['id_campagna_cliente']; ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header text-center">
<h4 class="modal-title w-100 font-weight-bold">Elimina Impianto</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<?php
$elimina=mysqli_query($connessione,"select * from campagne_cliente where id_campagna_cliente='".$row['id_campagna_cliente']."'");
$row_due=mysqli_fetch_array($elimina);
?>
<div class="modal-body mx-3">
<h5 style="text-align: center;">Eliminare Campagna di: <?php echo $row_due['nome'].' '?>?</h5>
</div>
<div class="modal-footer d-flex justify-content-center">
<a href="elimina.php?id_campagna_cliente=<?php echo $row['id_campagna_cliente']; ?>" class="btn btn-danger"><span class="glyphicon glyphicon-trash"></span>Elimina</a>
</div>
</div>
</div>
</div>
and this is the delete page from which I recover with $ _GET: id_campagna_cliente 这是我使用$ _GET从中恢复的删除页面:id_campagna_cliente
<?php
include '../../connessione.php';
$id_campagna_cliente=$_GET['id_campagna_cliente'];
mysqli_query($connessione,"DELETE * FROM campagne
LEFT JOIN campagne_cliente
ON campagne.id_campagna=campagne_cliente.id_campagna_cliente
WHERE campagne.id_campagna = '$id_campagna_cliente'");
header('location: campagne.php');
?>
but when I run delete it does not happen anything like it? 但是当我运行delete时,不会发生类似的事情吗? I would like to delete all the data contained in these two tables
我想删除这两个表中包含的所有数据
If you want to delete from multiple target tables using a delete join, then you need to specify all tables or aliases which you want to delete. 如果要使用删除联接从多个目标表中删除,则需要指定要删除的所有表或别名。 Something like this should work:
这样的事情应该起作用:
DELETE ca, cc
FROM campagne ca
LEFT JOIN campagne_cliente cc
ON ca.id_campagna = cc.id_campagna_cliente
WHERE
ca.id_campagna = ?;
You would then bind some value for id_campagna
in your PHP, ideally using a PHP prepared statement. 然后,
id_campagna
在PHP中为id_campagna
绑定一些值,最好使用PHP准备好的语句。
Note that DELETE *
is not valid as you were using it; 请注意,
DELETE *
在您使用时无效; only aliases are allowed to follow DELETE
, and then only in the context of a multi-table delete. 只允许别名跟随
DELETE
,然后只能在多表删除的上下文中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.