-
Notifications
You must be signed in to change notification settings - Fork 1
/
showbooking.php
170 lines (104 loc) · 3.78 KB
/
showbooking.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
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
<?php
require 'dbconfig.php';
// print("xxxxxxxxxxxxxxx");
// exit();
$table = "";
$userid = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$userid = isset($_POST["user"]) ? $_POST["user"] : "";
$table = isset($_POST["table"]) ? $_POST["table"] : "";
// $uname = isset($_POST["username"]) ? $_POST["username"] : "";
// $password = isset($_POST["password"]) ? $_POST["password"] : "";
// print("table: ");
// print($table);
// exit();
// print("userid: ");
// print("password: ");
// print($email);
// print($userid);
//echo "username and password: ",$uname,$pass;
}
$query = "select bookings.bookings_id,bookings.bookingTime,bookings.returnTime,bookings.passengers,car.name,
location.value, pickuplocation.pickUpLoc from pickuplocation, bookings,car,location where car.car_id = bookings.carNumber
and location.location_id=bookings.destination and pickuplocation.loc_id= bookings.pickupFrom and bookings.userid=$userid;";
//$query = "select * from $table where userid=$userid;";
//print_r($query);
//exit();
// $query = "select title,description,user_id from posts where posts.id='$post_id';";
$conn = new mysqli($hn, $un, $pw, $db);
//print_r($query);
//exit();
if ($conn->connect_error) {
// print("At line 49");
echo json_encode(array("value" => 0, "message" => 'Connection error with database, please try again '));
// die($connection->connect_error);
}
$result = $conn->query($query);
if (!$result) {
// echo json_error('Email not found please enter valid email.');
echo json_encode(array("value" => 0, "message" => 'Empty result returned from functions'));
// die($connection->error);
} elseif (0 == ($result->num_rows)) {
echo json_encode(array("value" => 0, "message" => '0 results returned from functions.'));
} else {
$num = $result->num_rows;
// $row = $result->fetch_array(MYSQLI_NUM);
// $row = $result->fetch_array(MYSQLI_ASSOC);
// print($row[0]);
// exit();
$id = '';
$value = '';
$index = 1;
// $oneLocation->id=0;
// $oneLocation->value='';
class vehicleBooking
{
public $bookings_id;
public $destination;
public $bookingtime;
public $PickUpLocation;
public $PassengerNumber;
public $CarName;
public $ReturnTime;
}
$arrayOfBookings = array();
while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
$bookings_id = ($row['bookings_id']);
$bookingtime = ($row['bookingTime']);
$ReturnTime = ($row['returnTime']);
$PassengerNumber = ($row['passengers']);
$CarName = ($row['name']);
$destination = ($row['value']);
$PickUpLocation = ($row['pickUpLoc']);
$oneInstance = new vehicleBooking();
$oneInstance->bookings_id = $bookings_id;
$oneInstance->bookingtime = $bookingtime;
$oneInstance->ReturnTime = $ReturnTime;
$oneInstance->PassengerNumber = $PassengerNumber;
$oneInstance->CarName = $CarName;
$oneInstance->destination = $destination;
$oneInstance->PickUpLocation = $PickUpLocation;
// print_r($oneInstance);
$arrayOfBookings[] = $oneInstance;
$index = $index + 1;
// exit();
// print($location);
// array_push($location, $x);
// print($location);
// $location[$index]->id=$id;
// $location[$index]->value = $value;
//
// $index++;
}
$myJSON = json_encode($arrayOfBookings);
//var_dump($arrayOfLocations);
// print_r($myJSON);
// exit();
//$myJSON = json_encode($location);
// echo json_encode($named_array);
echo json_encode(array("value" => 1, "message" => $myJSON));
// print($myJSON);
}
$conn->close();
// $result->close();
return $result;