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

The Archive Base Latest Questions

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

I have an input box where multiple words can be entered and searched for

  • 0

I have an input box where multiple words can be entered and searched for in my table.

supposing the user enters ‘people places things’ as their search criteria, these should get submitted to my php function which searches through my ‘nouns’ table and the ‘description’ and ‘title’ fields for possible matches. The function should then sort the results in descending order by number of matches found.

what I’ve got so far (missing a lot, and possibly not even the correct method):

$lcSearchVal = "people places things";
$lcSearchVal = explode( ' ', $lcSearchVal );

foreach( $lcSearchVal as $lcSearchWord ){
   $qry_suggest = mysql_query( 'SELECT * FROM nouns
                            WHERE Active 
                            AND ( ' . strpos($lcSearchWord, "description") > 0 . '
                               OR ' . strpos($lcSearchWord, "title") > 0 . ' ) '
                            );
}

I’m not sure what to do or where to go from here though….please help!

  • 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-21T14:38:32+00:00Added an answer on May 21, 2026 at 2:38 pm

    The query you are using will not work – you’re using PHP functions to do the comparison to a plain string and appending the result of that comparison in your query. All the DB will see is this:

    SELECT * FROM nouns WHERE Active AND (-1 OR 0)

    …because the php strpos function returns the numeric position of the found string (or -1 if not found. You need to use comparison functions within the database itself, therefore, you aren’t after php functions at all, rather you want mySQL comparison functions.

    For reference, here is a list of them: http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html

    Here is a sample that , very simply, searches for matches. You can improve this code quite a bit, but this should give you an idea:

    $lcSearchVal = "people places things";
    $lcSearchVal = explode( ' ', $lcSearchVal );
    
    $sql = 'SELECT * FROM nouns WHERE Active=1 AND (';
    
    $parts = array();
    foreach( $lcSearchVal as $lcSearchWord ){
        $parts[] = '`description` LIKE "%'.$lcSearchWord.'%"';
        $parts[] = '`title` LIKE "%'.$lcSearchWord.'%"';
    }
    
    $sql .= implode(' OR ', $parts).')';
    print $sql;
    

    Mess around with it: http://codepad.org/fcNH5qyu

    Also note, your WHERE Active clause is not valid – you have to give it a comparison. I’ve assumed in my sample that Active field is a numeric 1 or 0.

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

Sidebar

Related Questions

I have a string value from a user input box. I have to figure
I have the following file input box that allows for multiple upload: <input name=filesToUpload[]
I'm just an basic SQL user (mySQL+php now). I have search box with multiple
http://jsfiddle.net/nicktheandroid/yshcR/2/ you can type into the input box any of the words you see
I have an input box <input type=text name=search id=search /> <img src=icon.png alt= id=doSearch
I have an input box that takes values from 0-100. I want to prevent
I have an input box which I want to handle two types of information,
i have one form which have some input box and some select box. i
I'm new to jQuery and I want to have a input box from a
In my ASP.NET page, I have an input box that has to have the

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.