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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:41:06+00:00 2026-06-11T12:41:06+00:00

I currently have a simple search engine which searches a column in my database

  • 0

I currently have a simple search engine which searches a column in my database based on input from a user:

$search = $_GET['search'];
$terms = explode(" ", $search);

        $sql = "SELECT * FROM people WHERE lname LIKE :search";
    $q   = $conn->prepare($sql) or die("failed!");
    $q->bindValue(':search',"%".$search."%",PDO::PARAM_STR);
    $q->execute();

 if ($q){

 //
 do something

 }

Currently it is searching for terms as a whole, for example “red desk” returns a result BUT “desk red” does not return anything

Any ideas? Any help much appreciated!

EDIT:

I have since changed it to this…

   $search = $_GET['search'];
   $terms = explode(" ", $search);

        $sql = "SELECT * FROM people WHERE MATCH (lname,fname) AGAINST  (:search IN BOOLEAN MODE)";
    $q   = $conn->prepare($sql) or die("failed!");
    $q->bindValue(':search',"%".$search."%",PDO::PARAM_STR);
    $q->execute(); 

it seems to be working okay for now, if anyone could suggest a better solution i would be very thankful!

  • 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-06-11T12:41:07+00:00Added an answer on June 11, 2026 at 12:41 pm

    This might not be the best way but I think something like this might do the job. I would myself love to know if there’s a smarter way to do this!

    $search = $_GET['search'];
    $terms = explode(" ", $search);
    
    $sql = "SELECT * FROM people"
    if(count($terms) > 0) {
      $sql .= " WHERE (lname LIKE '%:term_0%' OR fname LIKE '%:term_0%')";
      for($i = 1; $i < count($terms); $i++)
        $sql .= " AND (lname LIKE '%:term_" . $i . "%' OR fname LIKE '%:term_" . $i . "%')";
    }
    
    $q = $conn->prepare($sql) or die("failed!");
    
    for($i = 0; $i < count($terms); $i++)
      $q->bindValue(':term_' . $i, $terms[$i]);
    $q->execute(); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a simple database program that reads keys in from a text
currently I have a simple search query which works as follows: $username = $_SESSION['username'];
I currently have a very simple MySQL database (articlesDB) with 1 table (articles) and
I have a very simple interface which needs to communicate between processes. It's currently
I have three tables associated and am trying to do a simple search. User
I'm trying to create a search engine for our library. Currently I have table
I have a search engine written in node.js/express that is currently not logging any
I currently have a simple form that when you click the save button will
Currently I have a simple knockoutJS object, with a few observables. But this object
Currently I have a simple maven project that is building a jar file and

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.