There is only one problem that tags without ( - ) are added to the database and therefore tags with ( - ) will not be displayed, but without ( - ) will work.
I’m adding labels with a minus sign but I don’t know if it’s correct or not
Example: tag-one, tag-two, tag-three
<?php include 'db.php'; ?>
<?php
if(isset($_GET['id']) && !empty($_GET['id'])){
$articleTags = intval($_GET['id']);
}else{
header('location:../404.php');
exit();
}
include 'config.php'; ?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>TITLE</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
a {
text-decoration: none;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<a href="../">home<a/>
<hr>
<p>Articles in tag: <?php echo htmlspecialchars($_GET['id']);?></p>
<hr>
<?php
$articleTags = str_replace(" ", "-", $articleTags);
$articleTags='%'.$_GET['id'].'%';
$stmt = $conn->prepare('SELECT articleId, articleTitle, articleTxt, articleTags FROM techno_blog WHERE articleTags like ? ORDER BY articleId DESC');
$stmt->bindValue(1, $articleTags);
$stmt->execute();
$posts = $stmt->fetch(PDO::FETCH_ASSOC);
?>
<!-- Tag -->
<div class="tags-section">
<ul class="list-inline tags">
<?php
$tags = explode(",", $posts['articleTags']);
foreach ($tags as $tag){ ?>
<?php echo "<a href='tag/".str_replace(" ", "-", $tag)."'>".$tag."</a>"; ?>
<?php
}
?>
</ul>
</div>
<!-- End tag-->
<h1 class="text-danger"><?php echo $posts['articleTitle']; ?></h1>
<p><?php echo $posts['articleTxt']; ?></p>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>