forked from edlcn/cs306db
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemployee_select.php
More file actions
72 lines (58 loc) · 1.8 KB
/
employee_select.php
File metadata and controls
72 lines (58 loc) · 1.8 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
<?php
include "config.php";
if (!empty($_GET["eid"])){
$eid = $_GET["eid"];
$sql_comment = "SELECT * FROM employee WHERE e_id = '".$eid."' ";
if (!empty($_GET["name"])) {
$pro = $_GET["name"];
$name = str_replace('+', ' ', $pro);
$sql_comment .= " AND name = '".$name."' ";
}
if (!empty($_GET["age"])) {
$age = $_GET["age"];
$sql_comment .= " AND age = '".$age."' ";
}
if (!empty($_GET["salary"])) {
$salary = $_GET["salary"];
$sql_comment .= " AND salary = '".$salary."' ";
}
$myresult = mysqli_query($db,$sql_comment);
while($rows = mysqli_fetch_assoc($myresult)){
echo $rows["e_id"] . " - " . $rows["name"] . " - " . $rows["age"] . " - " . $rows["salary"] . "<br>";
}
}
else {
$sql_comment = "SELECT * FROM employee ";
$hasWhere = false;
if (!empty($_GET["name"])) {
$pro = $_GET["name"];
$name = str_replace('+', ' ', $pro);
$sql_comment .= " WHERE name = '".$name."' ";
$hasWhere = true;
}
if (!empty($_GET["age"])) {
$age = $_GET["age"];
if($hasWhere) {
$sql_comment .= " AND age = '".$age."' ";
}
else {
$sql_comment .= " WHERE age = '".$age."' ";
$hasWhere = true;
}
}
if (!empty($_GET["salary"])) {
$salary = $_GET["salary"];
if($hasWhere) {
$sql_comment .= " AND salary = '".$salary."' ";
}
else {
$sql_comment .= " WHERE salary = '".$salary."' ";
$hasWhere = true;
}
}
$myresult = mysqli_query($db,$sql_comment);
while($rows = mysqli_fetch_assoc($myresult)){
echo $rows["e_id"] . " - " . $rows["name"] . " - " . $rows["age"] . " - " . $rows["salary"] . "<br>";
}
}
?>