So when i click the link ''What are SMTP, IMAP etc'' it should only show the article about SMTP but instead shows both articles. How do i show each article to their own titles?
right-column:
<div class="right-column">
<h3>Latest articles</h3>
<?php
$sql = "SELECT title, article_id FROM articles ORDER BY publish_date DESC LIMIT 10";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo ' <a href="article.php?articleID='.$row["article_id"].'">'.$row["title"].'</a> <br><br>';
}
}
?>
</div>
article.php:
<div class="article-info">
<?php
$sql = "SELECT * FROM articles INNER JOIN users ON articles.author = users.user_name ";
$result = $conn->query($sql);
if($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
if (isset($_GET["articleID"])) {
$id = $_GET["articleID"];
if($id == 1){ // should only show Domain article
echo '<h2>'.$row["title"].'</h2>';
echo '<p>Created '.$row["publish_date"].' || By '.$row["first_name"].' '.$row["last_name"].' ('.$row["role"].')</p>';
echo $row["text"];
} else if($id == 2) { //should only show SMTP article
echo '<h2>'.$row["title"].'</h2>';
echo '<p>Created '.$row["publish_date"].' || By '.$row["first_name"].' '.$row["last_name"].' ('.$row["role"].')</p>';
echo $row["text"];
}
}
}
}
?>
</div>
which looks like this:
I tried using the WHERE clause in the sql:
$sql = "SELECT * FROM articles INNER JOIN users ON articles.author = users.user_name WHERE article_id = 1";
but it prints the same article for both links