Display recommended blog posts | Next 5 rows data in PHP -Part 8

In this tutorial, we are going to display the recommended post using PHP and MYSQL. To display a recommended blog post, you have to use the PHP operator. Here we are learning to create a complete blog from the first tutorials "how to create a blog from scratch in PHP". In this tutorial, we will learn to display the recommended blog post. Displaying the next 5 or 6 posts is called the recommended blog post. The recommended post is meant for visitors and which can be beneficial posts. To display the recommended post, we will create an MYSQL query in such a way that the next 5 or 10 rows can be fetched on the same page. Displaying next row data on a current open blog post is called a recommended post.

Next 5 or 10 blog posts can be easily displayed by PHP and MYSQL. Along with displaying the next data, the data limit can also be set.


Fetch recommended Blog post from MYSQL database table –


To fetch the recommended post, an ID of the current blog post is required, due to which the next data can be fetched from the database. Like
Suppose – blog post id is 2
Let's understand the MYSQL query –

SELECT * from table_name where articleId>2 order by articleId ASC ;  


In the MYSQL query above, we are used current blog post id to display the next recommended row data. We are used > PHP (greater than) operator to fetch the next rows data.


How to set the limit for next rows data in PHP?


We can set a limit of rows in PHP. The limit is another best way to create a boundary for rows data. Let’s create an MYSQL query for next rows data.

SELECT * from table_name where articleId>2 order by articleId ASC  limit 5;  


In the above, we are used to limiting 5. We can create limit 1, 2, 3,4,5,6….n

SELECT * from table_name where articleId>2 order by articleId ASC  limit 6;  
SELECT * from table_name where articleId>2 order by articleId ASC  limit 10;  

Now, back to the PHP blog and add the code below after the social share code.

blog/show.php

 

Recomended Posts:

<?php // run query//select by current id and display the next 5 questions $recom= $db->query("SELECT * from techno_blog where articleId>$articleIdc order by articleId ASC limit 5"); // look through query while($row1 = $recom->fetch()){ echo '

'.$row1['articleTitle'].'

'; } ?>


In the above code, you can see that we are displaying the next 5 blog posts on the same page. Here we have used the blog title and slug using the id of the current open blog post by fetching the next 5 rows data. Here we have set the limit as 5. The limit can be further increased to display more recommended posts.

Recommended Posts:-

Previous Posts:-