-
Notifications
You must be signed in to change notification settings - Fork 0
/
articles.php
76 lines (69 loc) · 2.74 KB
/
articles.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
<?php
require 'backend/conn.php';
require 'backend/session.php';
checkLoggedIn();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Articles List</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="css/articles.css">
<link rel="stylesheet" href="css/search.css">
</head>
<body>
<?php require 'header.php'; ?>
<div class="container">
<!-- Welcome Section -->
<section class="welcome-section">
<h1>Welcome to the Articles List!</h1>
<!-- Add any additional welcome content here -->
</section>
<!-- Search Functionality -->
<section class="search-btn">
<form action="index.php" method="GET">
<input name="query" type="search" placeholder="What are you looking for?">
<button type="submit">Search</button>
</form>
</section>
<!-- Articles List Section -->
<section class="articles-list">
<br>
<div class="article-list">
<!-- Article Items -->
<?php
$sql = $conn->query('SELECT * FROM articles ORDER BY added_date DESC limit 10');
$sql->execute();
$result = $sql->fetchAll(PDO::FETCH_ASSOC);
?>
<?php foreach($result as $article): ?>
<?php
$isql = $conn->query("SELECT * FROM images where image_id = '{$article["article_image"]}';");
$isql->execute();
$image = $isql->fetch(PDO::FETCH_ASSOC);
if ($image) {
$imageUrl = '/' . basename($image['url']);
$imageAlt = $image['alt'];
} else {
$imageUrl = '';
$imageAlt = '';
}
?>
<div class="article">
<img src="/CodeGenius/uploads<?php echo $imageUrl; ?>" alt="<?php echo $imageAlt; ?>">
<div class="article-info">
<h3><?php echo $article['article_title'] ?></h3>
<div class="button-group2">
<button class="like-btn">Like</button>
<button class="read-btn" onclick="window.location.href='./article_view?article_id=<?php echo $article['article_id']; ?>'">Read</button>
</div>
</div>
</div>
<?php endforeach ?>
</div>
</section>
</div>
</body>
</html>