Hi guys I have implemented a table that provides the output to report all members registered in the php website that I'm developing, the table itself provides that for each user that is shown on the display there are 3 fields, id, name and email, before field id, there is the presence of a checkbox, made dynamic with an if, which gives the administrator the ability to select one or more users and be able to delete them through the appropriate button, I report the code to show the correct operation
if for delete:
<?php
session_start();
include '../a/connessione.php';
if(isset($_POST['delete'])){
$checkbox = $_POST['check'];
for($i=0;$i<count($checkbox);$i++){
$del_id = $checkbox[$i];
$db ="DELETE FROM user WHERE id='".$del_id."'";
$q = mysqli_query($connessione, $db);
}
}
?>
table:
<form id="form" method="post" action="wordpress.php">
<div class="card card-cascade narrower">
<!--Card image-->
<div class="view gradient-card-header blue-gradient narrower py-2 mx-4 mb-3 d-flex justify-content-between align-items-center">
<div>
<button type="button" class="btn btn-outline-white btn-rounded btn-sm px-2"><i class="fa fa-th-large mt-0"></i></button>
<button type="button" class="btn btn-outline-white btn-rounded btn-sm px-2"><i class="fa fa-columns mt-0"></i></button>
</div>
<a href="" class="white-text mx-3">Video Wordpress</a>
<div>
<button type="button" class="btn btn-outline-white btn-rounded btn-sm px-2"><i class="fa fa-pencil mt-0"></i></button>
<a href="" type="submit" class="btn btn-outline-white btn-rounded btn-sm px-2" data-toggle="modal" data-target="#centralModalSuccess"><i class="fa fa-remove mt-0"></i></a>
<button href="" name="informazioni" type="button" class="btn btn-outline-white btn-rounded btn-sm px-2" data-toggle="modal" data-target="#info"> <i class="fa fa-info-circle mt-0"></i>
</button>
</div>
</div>
<!--/Card image-->
<div class="px-4">
<div class="table-wrapper">
<!--Table-->
<table class="table table-hover mb-0">
<!--Table head-->
<thead>
<tr>
<th>
<input type="checkbox" id="checkbox">
</th>
<th class="th-lg"><a>ID </a></th>
<th class="th-lg"><a href="">Nome</a></th>
<th class="th-lg"><a href="">Email</a></th>
</tr>
</thead>
<!--Table head-->
<div style="text-align: center;"><?php if(isset($messaggio)) { echo $messaggio; } ?>
</div>
<!--Table body-->
<?php
while($row = mysqli_fetch_assoc($query)){ ?>
<tbody>
<tr>
<th scope="row">
<input name="check[]" type="checkbox" id="<?php echo $row['id'] ;?>" value="<?php echo $row['id'] ;?>">
<label for="<?php echo $row['id'] ;?>" class="label-table"></label>
</th>
<td><?php echo $row['id'] ;?><br></td>
<td><?php echo $row['nome'] ;?><br></td>
<td><?php echo $row['email'] ;?><br></td>
</tr>
</tbody> <?php } ?>
<!--Table body-->
</table>
<!--Table-->
</div>
<hr class="my-0">
<!--Bottom Table UI-->
<div class="d-flex justify-content-between">
<!--Pagination -->
<nav class="my-4">
<ul class="pagination pagination-circle pg-blue mb-0">
<!--First-->
<li class="page-item disabled"><a class="page-link">First</a></li>
<!--Arrow left-->
<li class="page-item disabled">
<a class="page-link" aria-label="Previous">
<span aria-hidden="true">«</span>
<span class="sr-only">Previous</span>
</a>
</li>
<!--Numbers-->
<li class="page-item active"><a class="page-link">1</a></li>
<li class="page-item"><a class="page-link">2</a></li>
<li class="page-item"><a class="page-link">3</a></li>
<li class="page-item"><a class="page-link">4</a></li>
<li class="page-item"><a class="page-link">5</a></li>
<!--Arrow right-->
<li class="page-item">
<a class="page-link" aria-label="Next">
<span aria-hidden="true">»</span>
<span class="sr-only">Next</span>
</a>
</li>
<!--First-->
<li class="page-item"><a class="page-link">Last</a></li>
</form>
</ul>
</nav>
<!--/Pagination -->
</div>
<!--Bottom Table UI-->
</div>
</div>
image of my table table
now every time the user selects a checkbox that corresponds to a user's id, its value is taken and when I click on the delete icon x opens a modal, when the modal premento on the delete button is opened user or multiple users that have been selected by the checkbox
and this works beautifully
I put the modal code with the relative delete button that refers to the if cycle
<!-- MODALE ELIMINAZIONE UTENTE/I -->
<div class="modal fade" id="centralModalSuccess" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-notify modal-success" role="document">
<!--Content-->
<div class="modal-content">
<!--Header-->
<div class="view gradient-card-header blue-gradient narrower py-2 mx-4 mb-3 d-flex justify-content-between align-items-center">
<p class="heading lead">Eliminazione Utenti</p>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true" class="white-text">×</span>
</button>
</div>
<!--Body-->
<div class="modal-body">
<div class="text-center">
<i class="fa fa-check fa-4x mb-3 animated rotateIn"></i>
<p>Tramite la tabella che riporta i tuoi dati, avrai la possibilità di poter eliminare i tuoi contenuti, selezionandoli e premendo su "elimina utente" una volta premuto, l'azione sarà irreversibile e al primo aggiornamento della pagina i cambiamenti verranno applicati.</p>
</div>
</div>
<!--Footer-->
<div class="modal-footer justify-content-center">
<button type="submit" name="delete" class="btn btn-primary">Elimina Utente</button>
<a type="button" class="btn btn-outline-primary waves-effect" data-dismiss="modal">Non eliminare</a>
</div>
</div>
<!--/.Content-->
</div>
</div>
<!-- MODALE ELIMINAZIONE UTENTE/I -->
<script type="text/javascript">$("#info").on('show.bs.modal', function(){
alert("Hello World!");
}); </script>
and now after having put all the code and having explained the modality with which I have arrived to accomplish this, I explain you my problem, taking in reference the image that I have inserted you will notice that besides the icon of elimination there are others two, the one that now interests me to make dynamic is the icon concerning the info, my goal would be that the selection of one or more users with the checkbox and the click of the info icon, another modal would appear that showed on display, all the information concerning the users that have been selected, to do this I thought it was enough to implement a further if or else with respect to the cycle I had written before
then use again the input check [] that I entered in the table code but tell him when this other button is pressed instead of deleting show me his information and I tried in this way
<?php
session_start();
include '../a/connessione.php';
if(isset($_POST['delete'])){
$checkbox = $_POST['check'];
for($i=0;$i<count($checkbox);$i++){
$del_id = $checkbox[$i];
$db ="DELETE FROM user WHERE id='".$del_id."'";
$q = mysqli_query($connessione, $db);
if (isset($_POST['informazioni'])) {
$checkbox = $_POST['check'];
for($i=0;$i<count($checkbox);$i++){
$del_id = $checkbox[$i];
$db ="SELECT * FROM user WHERE id='".$del_id."'";
}
}
}
}
?>
button code :
<button href="" name="informazioni" type="button" class="btn btn-outline-white btn-rounded btn-sm px-2" data-toggle="modal" data-target="#info"> <i class="fa fa-info-circle mt-0"></i>
</button>
modal code:
<!-- MODALE INFORMATION UTENTE/I -->
<div class="modal fade" id="info" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-notify modal-success" role="document">
<!--Content-->
<div class="modal-content">
<!--Header-->
<div class="view gradient-card-header blue-gradient narrower py-2 mx-4 mb-3 d-flex justify-content-between align-items-center">
<p class="heading lead">Eliminazione Utenti</p>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true" class="white-text">×</span>
</button>
</div>
<!--Body-->
<div class="modal-body">
<div class="text-center">
<i class="fa fa-check fa-4x mb-3 animated rotateIn"></i>
<?php
while($dati = mysqli_fetch_assoc($q)){ ?>
<?php echo $dati['nome'] ;?>
<?php } ?>
</div>
</div>
<!--Footer-->
<div class="modal-footer justify-content-center">
<button type="submit" name="#" class="btn btn-primary">Elimina Utente</button>
<a type="button" class="btn btn-outline-primary waves-effect" data-dismiss="modal">Non eliminare</a>
</div>
</div>
<!--/.Content-->
</div>
</div>
<!-- MODALE INFORMATION UTENTE/I -->
but this does not work, my question is how do I take advantage of the same input as the checkbox = check [] but give it a different command based on the icons I press with an if? thank you
Aucun commentaire:
Enregistrer un commentaire