-
Notifications
You must be signed in to change notification settings - Fork 0
/
Advanced_Customer.php
106 lines (76 loc) · 2.05 KB
/
Advanced_Customer.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
<?php
$errors = [];
$data = [];
$string = "";
$Fname = $_POST['Fname'];
$Lname = $_POST['Lname'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$street = $_POST['street'];
$city = $_POST['city'];
$country = $_POST['country'];
if (!empty($Fname)) {
if ($string != "") {
$string = $string . "AND ";
}
$string = $string . "first_name= '" . $Fname . "'";
}
if (!empty($Lname)) {
if ($string != "") {
$string = $string . "AND ";
}
$string = $string . "last_name= '" . $Lname . "'";
}
if (!empty($email)) {
if ($string != "") {
$string = $string . "AND ";
}
$string = $string . "email= '" . $email . "'";
}
if (!empty($phone)) {
if ($string != "") {
$string = $string . "AND ";
}
$string = $string . "phone_no= '" . $phone . "'";
}
if (!empty($street)) {
if ($string != "") {
$string = $string . "AND ";
}
$string = $string . "Street_name= '" . $street . "'";
}
if (!empty($city)) {
if ($string != "") {
$string = $string . "AND ";
}
$string = $string . "city= '" . $city . "'";
}
if (!empty($country)) {
if ($string != "") {
$string = $string . "AND ";
}
$string = $string . "country= '" . $country . "'";
}
if ($string != "") {
$string = "WHERE " . $string;
}
$connection = mysqli_connect('localhost', 'root', '', 'car_rental_system');
$query = mysqli_query($connection, "SELECT * FROM customer $string ");
$num_rows = mysqli_num_rows($query);
$i = 0;
if ($num_rows != 0) {
while ($row = mysqli_fetch_assoc($query)) {
$response[$i]['id'] = $row['customer_id'];
$response[$i]['fn'] = $row['first_name'];
$response[$i]['ln'] = $row['last_name'];
$response[$i]['e'] = $row['email'];
$response[$i]['phn'] = $row['phone_no'];
$response[$i]['st'] = $row['Street_name'];
$response[$i]['ct'] = $row['city'];
$response[$i]['ctr'] = $row['country'];
$data[$i] = $response[$i];
$i += 1;
}
}
mysqli_close($connection);
echo json_encode($data);