Ghamdan Posted October 27, 2012 Share Posted October 27, 2012 I have got a posts table with columns of title, author and content. Indeed I want to retrieve 3 post titles related to the one is viewed at the end of the post. The question is: How can I retrieve related posts using php and mysql? Thank you. Link to comment Share on other sites More sharing options...
Edward Posted October 27, 2012 Share Posted October 27, 2012 What does this mean exactly "Indeed I want to retrieve 3 post titles related to the one is viewed at the end of the post." If you are retrieving related posts you will need to check to see if the current post has a parent_id which is equal to the post_id. You will need an extra column in your posts table parent_id to do this, you will also need the post_id column which is a primary key and set to auto increment. Link to comment Share on other sites More sharing options...
HartleySan Posted October 27, 2012 Share Posted October 27, 2012 When you initially load the page with the original post, you need to do whatever is necessary to figure out what the topic of the original post is. This will depend a lot on your site logic and DB structure, so I can't really advise you much beyond that. Anyway, once you know what the original post is about, then you need to make a query at the bottom of the page to get the relevant posts and put them up. Link to comment Share on other sites More sharing options...
Ghamdan Posted October 28, 2012 Author Share Posted October 28, 2012 I want to display some related posts when a post is viewed. For example if the post is about windwos 8 then some related posts to windows 8 will be displayed and so on. This is main idea. How can I implement this feature using php and mysql? Thank you. Link to comment Share on other sites More sharing options...
HartleySan Posted October 28, 2012 Share Posted October 28, 2012 Ghamdan, I think I already answered your question, but when you're first loading the post (i.e., running the PHP script to get the original post), you need to establish what the post is about (e.g., Windows 8), and then query the DB in the same script for related posts, and posted them below the original post. Link to comment Share on other sites More sharing options...
Recommended Posts