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

  • Home
  • SEARCH
  • 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 6726601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:56:47+00:00 2026-05-26T09:56:47+00:00

I have a PHP keyword search script that searches a MySQL database and then

  • 0

I have a PHP keyword search script that searches a MySQL database and then displays the results. Currently, the script finds results based on a single keyword attached to a field in a MySQL database.

My question is; how can I attach multiple keywords to one field and return results if one or more of those keywords is matched in the users query?

Can I define the keywords in my database and separate them with commas? e.g. this, would, be, in, the, field

<?php

mysql_connect("localhost","username","password");
mysql_select_db("database");

if(!empty($_GET['q'])){
$query=mysql_real_escape_string(trim($_GET['q']));
$searchSQL="SELECT * FROM questions WHERE `keywords` LIKE '%{$query}%'  LIMIT 1";
$searchResult=mysql_query($searchSQL);

while($row=mysql_fetch_assoc($searchResult)){
$results[]="{$row['result']}";
}

echo implode($results);
}

?>
  • 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-26T09:56:47+00:00Added an answer on May 26, 2026 at 9:56 am

    Either use a fulltext index, or split the keyword list into a compound “where like … or like … or like …” statement:

    $keywords = explode(' ', $_GET['q']);
    $likes = array()
    foreach($keywords as $kw) {
       $kw = mysql_real_escape_string($kw);
       $likes[] = "keywords LIKE '%{$kw}%'";
    }
    
    $sql = "SELECT ... WHERE " . implode(' OR ', $likes);
    

    Storing compound data in a single field in a relational database is rarely a good idea, especially if you’re going to need to access sub-portions of the whole field. Keywords should be stored in a separate table, one keyword per record. You can then use a link table to relate multiple keywords to each individual record in your parent table.

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

Sidebar

Related Questions

I have a PHP search script that queries a MySQL database and then parses
I have been writting a keyword search script based on this tutorial: http://www.hackosis.com/2007/11/06/howto-simple-search-engine-with-php-and-mysql/ Like
I have php script that creates a temporary watermark image for users that are
I have PHP scrip that goes like this: if ($cost_frm < $cost){ echo <script
I have a search feature using PHP that offers either the option to search
I currently have the following code: <form action=process.php method=POST> <fieldset class=form-search> <input type=text class=input-text
I have an application that stores data in database. I need search functionality to
In my tag cloud I have urls that look like this ../search.php?query=cat&select=all ../search.php?query=the cat&select=all
I have a SQL database of website names/links/keywords. I then PHP query the database,
I have a jquery.ajax routine that calls a php script. The php script does

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.