-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetHistory.php
45 lines (32 loc) · 1.02 KB
/
getHistory.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
<?php
require "DataBaseConfig.php";
$dbC = new DataBaseConfig();
$servername = $dbC->servername;
$dbusername = $dbC->username;
$dbpassword = $dbC->password;
$dbname = $dbC->databasename;
$heroes = array();
if (isset($_POST['counter_num'])) {
$counter_num = $_POST['counter_num'];
$conn = new mysqli($servername, $dbusername, $dbpassword, $dbname);
if ($conn->connect_errno) {
die("connection faild: " . $conn->connect_errno);
}
$sql = "SELECT new_index,date FROM collect INNER JOIN counter ON collect.counter_num = counter.counter_num WHERE collect.counter_num = ? ORDER BY id DESC";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $counter_num);
$stmt->execute();
$stmt->bind_result($new_index, $date);
while ($stmt->fetch()) {
//pushing fetched data in an array
$temp = [
'new_index' => $new_index,
'date' => $date
];
//pushing the array inside the hero array
array_push($heroes, $temp);
}
echo json_encode($heroes);
} else {
echo "All fields are required";
}