-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharticle.php
61 lines (53 loc) · 1.67 KB
/
article.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
<?php
// Establish database connection
$servername = "localhost";
$username = "YOUR_DB_USERNAME";
$password = "YOUR_DB_PASSWORD";
$dbname = "YOUR_DB_NAME";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Retrieve the article ID from the query parameter
if (isset($_GET['id'])) {
$articleId = $_GET['id'];
} else {
die("Article ID not provided.");
}
// Fetch the article from the database
$selectQuery = "SELECT * FROM news WHERE id = $articleId";
$result = $conn->query($selectQuery);
if ($result->num_rows > 0) {
$article = $result->fetch_assoc();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<title><?php echo $article['title']; ?></title>
</head>
<body>
<nav>
<div class="nav-wrapper blue">
<a href="/" class="brand-logo center">India News</a>
</div>
</nav>
<div class="container">
<div class="card">
<div class="card-content">
<span class="card-title"><?php echo $article['title']; ?></span>
<p><?php echo $article['description']; ?></p>
<a href="<?php echo $article['url']; ?>" target="_blank" class="btn">Read Full Article</a>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
</body>
</html>
<?php
} else {
echo "Article not found.";
}