Creating the slug page
***********************
1. Add the header to the table <th>View post</th>
go to tbody and Add <td><a href="posts.php?slug=<?php echo $row['slug'];
?>">view post</td>
2. Make the page posts.php
and get the slug variable
$slug = $_GET['slug']
We need make preety url so we use htaccess
and write the write Rule for Query String of Get Request
RewriteRule ^(posts)/([a-z0-9\-]+)$ posts.php?slug=$2 [QSA]
Now Change the Url in show.php
<a href="posts/<?php echo $row['slug'] ?>">
<?php
$slug=$_GET['slug'];
include __DIR__.'/config/dbconnect.php';
$sql = "Select * from tbl_post where slug = '$slug'";
$result_set = mysqli_query($con,$sql);
$count = mysqli_num_rows($result_set);
if($count > 0){
if($row=mysqli_fetch_assoc($result_set)){
$title = $row['title'];
$date = $row['date'];
$time = $row['time'];
$content = $row['content'];
}
}else{
echo "<h1>404 Search Result does not Match </h1>";
exit;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>:: POSTS || <?php echo $title; ?> </title>
</head>
<body>
<h1><?php echo $title; ?></h1>
<hr>
<div>
<?php echo $content?>
</div>
<div>
<samp>Added By Admin: On <?php echo $date; ?> at <?php echo $time; ?>
</samp>
</div>
</body>
</html>
0 Comments