Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1053447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:15:15+00:00 2026-05-16T17:15:15+00:00

I was looking around SO and was wondering how would I go about in

  • 0

I was looking around SO and was wondering how would I go about in creating a related or similar posts to display on my web site using PHP & MySQL? What is a basic example of how to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T17:15:16+00:00Added an answer on May 16, 2026 at 5:15 pm

    Using the MySQL Full Text search MATCH (col1,col2,...) AGAINST (expr [search_modifier]) thing.

    Let’s say your table is articles and you need to find related posts about a title of current post. Do it like this:

    SELECT *, MATCH(title, body) AGAINST('$CurrentPostTitle') AS score
    FROM articles 
    WHERE MATCH(title, body) AGAINST('$CurrentPostTitle') 
    ORDER BY score DESC LIMIT 5
    

    This will give you top 5 related posts.

    But first remember to enabled Full Text search for that table’s columns, by running this query:

    ALTER TABLE articles ADD FULLTEXT (title, body);
    

    [EDIT]: Why to not use LIKE: Clarification to OP:

    Because it will not give correct results. Let’s say you current title is “Music of 1980” and you want related posts on that. Now, if you use LIKE then only the posts containing EXACTLY the sequence of words “Music of 1980” will appear. However, if you use MATCH ... AGAINST, then posts that contain Music OR 1980 will appear. Also, the posts that contain both Music and 1980 will appear on Top because it gives a SCORE to each results and we are sorting by that score.I hope that’s clear.

    [EDIT]: 2:

    If you have categories, you can add AND Category = '$CurrentCategory' in the SQL query where clause to get more specific results.

    [EDIT]: 3: OP can’t use Full text:

    If you can not use Full Text (for some reason), you can just show 5 random posts from the same category. As they are in same category, they are somehow related at least:

    SELECT *
    FROM articles 
    WHERE Category = '$CurrentCategory'
    LIMIT 5
    

    Edited Syntax: Changed LIMTI to LIMIT in MySQL Code

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm playing around with LINQ and related subjects and was wondering about the following.
Looking around, I can't name a single web application (not web service) that uses
I have been looking around for a visualization framework that would aid graph visualization
I was wondering if anyone can help me, I've been looking around for regex
we're looking at add a new feature to our site which would allow users
I'm asking this question here because after looking around the web for answers, I
I'm looking into using FluentNHibernate as my ORM but I'm wondering how best to
I was recently looking around at some of the features my current web host
Been looking around and can't find a definite way to do this... I need
After looking around (for not terribly long I have to admit) I wonder if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.