-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfetch.php
66 lines (53 loc) · 1.42 KB
/
fetch.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
<?php
/**
* Created by PhpStorm.
* User: Adnan
* Date: 2/27/2020
* Time: 8:10 PM
*/
include("config.php");
$user_id = $_POST['user_id'];
if (!empty($user_id)) {
$sql = "SELECT * FROM `posts` WHERE `user_id` = " . $user_id;
$result = $conn->query($sql);
$result = mysqli_fetch_all($result, MYSQLI_ASSOC);
if (!empty($result)) {
// output data of each row
$markup = [];
foreach ($result as $single) {
$markup[] = '<div class="posting"><h1>' . $single["post_title"] . '</h1><p>' . $single["post_content"] . '</p></div><hr>';
}
$data = [
"user_id" => $user_id,
"posts" => $markup,
];
} else {
$data = [
"user_id" => $user_id,
"posts" => "",
];
}
} else {
$data = [
"user_id" => "",
"posts" => "",
];
}
if (!empty($data['posts'])) {
foreach ($data['posts'] as $single) {
$file = 'template.html';
// Open the file to get existing content
$current = file_get_contents($file);
// Append a new person to the file
$current .= "<!doctype html><html>
<head><meta charset='utf-8'>
<title>Template</title>
</head><body> <p>" . $single . "</p>
</body></html>
";
// Write the contents back to the file
file_put_contents($file, $current);
}
}
echo json_encode($data);
exit();