-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
136 lines (115 loc) · 4.74 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Çoklu SİL</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<script src="deleteall.js"></script>
<?php
include('fonc.php'); // We include our database on our page
if (isset($_POST['delete'])) { // Checking if the deletion Checkbox is Checked
$selecteddata = implode(', ', $_POST['delete']); // We pass it to the variable "$selecteddata" that comes with Checkbox
$query = $connect->prepare('select * FROM `blog` WHERE `id` IN (' . $selecteddata . ')'); // We get the IDs from the database
$query->execute(); //executing query and getting data
while ($result = $query->fetch()) { // Incoming data is returned with a while loop
@unlink('img/' . $result["photo"]);// Old files (photos) are deleted. optional, you can not use this code
}
$query = $connect->prepare('DELETE FROM `blog` WHERE `id` IN (' . $selecteddata . ')'); // Our deletion query according to incoming data IDs
$query->execute(); // Running Query
if ($query) { // If our query worked, we are redirecting to our index.php page
header("location:index.php");
}
}
?>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-8">
<!-- We add a Form to our table, it must be a Form, otherwise the data will not be posted, it will not work. -->
<form action="" method="post">
<!-- Our table-->
<table class="table table-hover">
<!-- We make our Selected Delete Button to give a Warning with Modal.-->
<a class="btn btn-danger font-18" href="#" data-toggle="modal"
data-target="#deleteall"><i class="fa fa-trash"> Delete Selected Data</i></a>
<!-- Logout Modal-->
<div class="modal fade" id="deleteall" tabindex="-1" role="dialog"
aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Delete All Action</h5>
<button class="close" type="button" data-dismiss="modal"
aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<h1 class="text-center">Important Warning !</h1>
<h3 class="text-center">The selected data will be deleted. Do you approve</h3></div>
<div class="modal-footer">
<button type="submit" class="btn btn-danger font-18 "><i class="fa fa-trash"> Delete selected ones</i></button>
<button class="btn btn-secondary" type="button"
data-dismiss="modal">Cancel
</button>
</div>
</div>
</div>
</div> <!-- End of our delete selected modal-->
<thead class="thead-dark">
<th>
<!--Select All at the Top of Our Table We place our checkbox in the thead part of our table-->
<div class="checkbox">
<input type="checkbox" id="selectall" value=""> <!--We give an id to our Checkbox and select all of them with javascript codes. -->
</div>
</th>
<th>ID</th>
<th>photo</th>
<th>Title</th>
<th>Content</th>
</thead>
<?php
$query = $connect->prepare("SELECT * FROM blog"); // Retrieving data from database
$query->execute(); // Running Our Query
while ($result=$query->fetch()) // Data from database is returned with While Loop.
{ // With the start we have data
?>
<tbody>
<td>
<!--We use Checkbox to identify deleted Dataz-->
<div class="checkbox">
<input class="chck" type="checkbox" name="delete[]"
value="<?php echo $result['id']; ?>"><!--We specify a name for the "name" part of the checkbox to be recognized for our multiple deleteme query.-->
<label for="<?php echo $result['id']; ?>"></label> <!--We are sending the ID from the database to Checkbox-->
</div>
</td>
<td><?= $result['id']?></td>
<th><img src="img/<?= $result["photo"] ?>" width="150px"/></th>
<td><?= $result['title']?></td>
<td><?= $result['content']?></td>
</tbody>
<?php
} // With End of While, we pull our data and our query ends.
?>
</table>
</form>
</div>
</div>
</div>
<!--When we click on the "deleteall" checkbox, we add our javascript code so that all checkboxes are checked-->
<script type="text/javascript">
$(document).ready(function () {
$('#selectall').on('click', function () {
if ($('#selectall:checked').length == $('#selectall').length) {
$('input.chck:checkbox').prop('checked', true);
} else {
$('input.chck:checkbox').prop('checked', false);
}
});
});
</script>
<script src="js/jquery-3.4.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>