<!DOCTYPE html> <html> <head> <meta charset="utf-8" name="viewport" content="width=device-width, intial-scale=1"/> <link rel="stylesheet" type="text/css" href="css/bootstrap.css"> </head> <body> <nav class="navbar navbar-default"> <div class="container-fluid"> <a class="navbar-brand" href="https://sourcecodester.com">Sourcecodester</a> </div> </nav> <div class="col-md-3"></div> <div class="col-md-6 well"> <h3 class="text-primary">PHP - Simple Delete Data In XML File</h3> <hr style="border-top:1px dotted #ccc;"/> <table class="table table-bordered table-striped" style="margin-top:20px;"> <thead class="alert-info"> <th>Student ID</th> <th>Firstname</th> <th>Lastname</th> <th>Address</th> <th>Action</th> </thead> <tbody> <?php foreach($file->student as $row){ ?> <tr> <td><?php echo $row->stud_id; ?></td> <td><?php echo $row->firstname; ?></td> <td><?php echo $row->lastname; ?></td> <td><?php echo $row->address; ?></td> <td><a href="#delete_<?php echo $row->stud_id; ?>" data-toggle="modal" class="btn btn-danger"><span class="glyphicon glyphicon-remove"></span> Delete</a></td> </tr> <div class="modal fade" id="delete_<?php echo $row->stud_id; ?>" role="dialog" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h4 class="modal-title">System Information</h4> </div> <div class="modal-body"> <center><h3 class="text-danger">Are you sure you want to Delete this record?</h3></center> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span> Close</button> <a href="delete.php?id=<?php echo $row->stud_id; ?>" class="btn btn-danger"><span class="glyphicon glyphicon-trash"></span> Yes</a> </div> </div> </div> </div> <?php } ?> </tbody> </table> </div> <script src="js/jquery-3.2.1.min.js"></script> <script src="js/bootstrap.js"></script> </body> </html>
<?php $id = $_GET['id']; $position = 0; $i = 0; foreach($students->student as $student){ if($student->id == $id){ $position = $i; break; } $i++; } ?>