-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist_all.php
More file actions
233 lines (191 loc) · 5.36 KB
/
list_all.php
File metadata and controls
233 lines (191 loc) · 5.36 KB
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<?php
session_start();
if(!isset($_SESSION["username"])){
header("location: login.php");
exit;
}
?>
<html>
<head>
<title>List All Items</title>
</head>
<body>
<?php
function listAll(){
echo "<form action = './add_item.php' method = 'POST'>";
echo "<button type = 'submit'> Add Item </button>";
echo "</form>";
//establish a connection to the database
$connection = mysqli_connect("localhost", "root", "", "inventory");
//check if the connection was successful
if($connection)
{
$sql = " select
item.iid,
item.description,
item.umsr,
category.description,
item.qtyonhand,
item.price
from
item left join category
on item.cid = category.cid
order by
item.description
";
$records = mysqli_query($connection, $sql);
if(mysqli_num_rows($records) > 0)
{
echo "<table border='1'>";
echo " <tr>";
echo " <th>Seq. No.</th>";
echo " <th>Item ID</th>";
echo " <th>Description</th>";
echo " <th>Unit of Measure</th>";
echo " <th>Category</th>";
echo " <th>Qty. on Hand</th>";
echo " <th>Price</th>";
echo " <th colspan ='2'>Action</th>";
echo " </tr>";
$seq = 1;
while($rec = mysqli_fetch_array($records))
{
echo "<tr>";
echo " <td>".$seq.".</td>";
echo " <td>".$rec[0]."</td>";
echo " <td>".$rec[1]."</td>";
echo " <td>".$rec[2]."</td>";
if($rec[3] === null){
echo " <td>Category Deleted</td>";
}else{
echo " <td>".$rec[3]."</td>";
}
if(fmod($rec[4],1) === 0.00){
echo " <td align='right'>".floor($rec[4])."</td>";
}else{
echo " <td align='right'>".$rec[4]."</td>";
}
echo " <td align='right'>".$rec[5]."</td>";
echo " <td><a href='list_all.php?deleteId= ".$rec[0]."'>🗑 Delete</a></td>";
echo " <td><a href='./update_item.php?updateId=".$rec[0]."'>🖉 Update</a></td>";
echo "</tr>";
$seq++;
}
echo "</table>";
}
else
{
echo "<p>No records found...</p>";
}
}
else
{
echo "<p>Error connecting to DB...</p>";
}
mysqli_close($connection);
}
function searchBar(){
echo '<form method="GET" action="list_all.php">';
echo '<input type="text" name="keyword" value="" placeholder="Type keyword here..." />';
echo '<button type="submit" name="search">Search</button>';
echo '</form>';
}
searchBar();
listAll();
if(isset($_GET["search"]))
{
ob_end_clean();
$keyword = trim($_GET["keyword"]);
//search bar
searchBar();
//add item
echo "<form action = './add_item.php' method = 'POST'>";
echo "<button type = 'submit'> Add Item </button>";
echo "</form>";
//establish a connection to the database
$connection = mysqli_connect("localhost", "root", "", "inventory");
//check if the connection was successful
if($connection)
{
//get all the records from the student table
$records = mysqli_query($connection,
" select
item.iid,
item.description,
item.umsr,
category.description,
item.qtyonhand,
item.price
from
item left join category
on item.cid = category.cid
where
item.description like '%".$keyword."%' or price like '%".$keyword."%'
order by
item.description");
//check if there are records retrieved
if(mysqli_num_rows($records) > 0)
{
echo "<table border='1'>";
echo " <tr>";
echo " <th>Seq. No.</th>";
echo " <th>Item ID</th>";
echo " <th>Description</th>";
echo " <th>Unit of Measure</th>";
echo " <th>Category</th>";
echo " <th>Qty. on Hand</th>";
echo " <th>Price</th>";
echo " <th colspan ='2'>Action</th>";
echo " </tr>";
$seq = 1;
while($rec = mysqli_fetch_array($records))
{
echo "<tr>";
echo " <td>".$seq.".</td>";
echo " <td>".$rec[0]."</td>";
echo " <td>".$rec[1]."</td>";
echo " <td>".$rec[2]."</td>";
if($rec[3] === null){
echo " <td>Category Deleted</td>";
}else{
echo " <td>".$rec[3]."</td>";
}
if(fmod($rec[4],1) === 0.00){
echo " <td align='right'>".floor($rec[4])."</td>";
}else{
echo " <td align='right'>".$rec[4]."</td>";
}
echo " <td align='right'>".$rec[5]."</td>";
echo " <td><a href='list_all.php?deleteId= ".$rec[0]."'>🗑 Delete</a></td>";
echo " <td><a href='./update_item.php?updateId=".$rec[0]."'>🖉 Update</a></td>";
echo "</tr>";
$seq++;
}
echo "</table>";
}
else
{
echo "<p>No records found...</p>";
}
}
else
{
echo "<p>Error connecting to DB...</p>";
}
mysqli_close($connection);
}
if(isset($_GET["deleteId"]))
{
$id = $_GET["deleteId"];
ob_end_clean();
searchBar();
//establish a connection to the database
$connection = mysqli_connect("localhost", "root", "", "inventory");
mysqli_query($connection, "delete from item where iid = '".$id."' ");
echo "<p>Deleted successfully...</p>";
mysqli_close($connection);
listAll();
}
?>
</body>
</html>