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 7308937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T23:38:31+00:00 2026-05-28T23:38:31+00:00

I have a query that gets comments from a database and displays them based

  • 0

I have a query that gets comments from a database and displays them based on what the user typed in.

PHP:

$query=mysql_query("SELECT * FROM comments WHERE MATCH (comments) AGAINST ('%$user_text%')");
    while ($row=mysql_fetch_assoc($query)){
        echo "<div>$row['comment']</div>";
    }

This doesn’t return any values. It may be that the comments column in my mysql database isn’t set to FULLTEXT. i ran this script ALTER TABLE comments ADD FULLTEXT(comment); but i can’t verify that the index is indeed FULLTEXT

UPDATE (after verifying how table was created):

CREATE TABLE `comments` (
`id` int(11) NOT NULL...

 PRIMARY KEY (`id`),  //these are the last 3 lines
 FULLTEXT KEY `comments` (`comment`)
) ENGINE=MyISAM AUTO_INCREMENT=93 DEFAULT CHARSET=latin1
  • 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-28T23:38:31+00:00Added an answer on May 28, 2026 at 11:38 pm

    Think I got it. In your original query you are not specifying an optional modifier, which according to MySQL, means it defaults to IN NATURAL LANGUAGE MODE. And according to some docs I have read, and my own testing, IN NATURAL LANGUAGE MODE will only match ‘whole’ words.

    If you want to do partial string matching, you will have to use the IN BOOLEAN MODE modifier instead. However, there is a limitation in that MySQL cannot search using wildcards prepended to a search string, because they are indexed left-to-right, not right-to-left. So to get your search working, try this:

    SELECT * FROM comments WHERE MATCH (comments) AGAINST ('$user_text*' IN BOOLEAN MODE)"
    

    You can read up on boolean fulltext searches here.

    Also, you should read up on mysql_real_escape_string to sanitize variables going into your queries to protect from SQL injection attacks.

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

Sidebar

Related Questions

I have a query that gets places based on the Haversine algorithm. SELECT id,
I have a select query that gets a field and displays it with a
I have a standard query that gets the current user object: @user = User.find_by_email(session[:email])
Right now, I have a query that gets me 3 columns. SELECT a.studentID, a.classdetailID,
I have created a page called profile.php that gets a value from mainpage.php, by
I have a query in django that: gets the current category. based on that
I have an insert query that gets generated like this INSERT INTO InvoiceDetail (LegacyId,InvoiceId,DetailTypeId,Fee,FeeTax,Investigatorid,SalespersonId,CreateDate,CreatedById,IsChargeBack,Expense,RepoAgentId,PayeeName,ExpensePaymentId,AdjustDetailId)
I have a complex query that gets executed like this: if ($stmt = $dbi->prepare($pt_query))
I have a 5 million row table that gets hit with a specific query
I have a form that sometimes gets linked to with some query string parameters.

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.