-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpullContent.php
45 lines (38 loc) · 1.6 KB
/
pullContent.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
if (isset($_GET["postID"])){
$postID = $_GET["postID"];
$sql = "SELECT post.id as postID, author, title, catID, content, author.id as authorID, author.name as authorName, cat.name as catName, date FROM post JOIN author on author.id = author JOIN cat on cat.id = post.catID WHERE post.id = ?";// . $postID;
$stmt = $pdo->prepare($sql);
$stmt->execute([$postID]);
foreach ($stmt as $row)
{
echo "<h2>" . $row["title"] . "</h2>Posted By: " . $row["authorName"] . ", Posted In: " . $row["catName"] . ", at: " . $row["date"] . " EST.<br /><br />";
echo $row["content"];
}
}
elseif (isset($_GET["cat"])){
$cat = $_GET["cat"];
$sql = "SELECT post.id as postID, author, title, catID, content, author.id as authorID, author.name as authorName, cat.name as catName, cat.icon as catIcon, date FROM post JOIN author on author.id = author JOIN cat on cat.id = post.catID WHERE cat.cat = ? ORDER BY date DESC";
$stmt = $pdo->prepare($sql);
$stmt->execute([$cat]);
$rows = $stmt->fetchAll();
// Displays at top of category
if(count($rows)>0){
$catName = $rows[0]['catName'];
$catIcon = $rows[0]['catIcon'];
echo "<h1>{$catName}</h1>";
for ($i = 0; $i < strlen($catName); $i++){
echo "<i class='fa {$catIcon}'></i>";
}
}
foreach ($rows as $row)
{
echo "<h2>" . $row["title"] . "</h2>Posted By: " . $row["authorName"] . ", at: " . $row["date"] . " EST.<br /><br />";
echo $row["content"];
echo "<hr/>";
}
}
else{
include 'homeContent.php';
}
?>