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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:17:23+00:00 2026-06-10T06:17:23+00:00

I am a beginner in Mysql Php. I want to make a search box

  • 0

I am a beginner in Mysql Php. I want to make a search box which can find a row containing searching multiple words of a table in mysql. I have got a script via internet which is given below. When i type multiple words it show the row which have minimum a searching word. But I want that it will only show the row which have searching multiple words. Please Help me.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang='en'>
<head>
<META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=UTF-8'/>
<title>Page title</title>
<style type="text/css">
table {
border-collapse: collapse;
border: solid 1px black;
}
td {
padding: 2px 6px;
border: solid 1px black;
}
</style>
</head>
<body>
<form action='<?php echo $_SERVER['PHP_SELF']; ?>' method='post'>
<p>Search for: <input type='text' name='search' size='20'
maxlength='64'></p>
<p><input type='submit' value='Search'></p>
</form>
<?php
if(isset($_POST['search']))
{
$connx = mysql_connect('localhost', '*****', '*****') or
die("connx");
$db = mysql_select_db('test') or die(mysql_error());
# convert to upper case, trim it, and replace spaces with "|":
$search = (ini_get('magic_quotes_gpc')) ?
stripslashes($_POST['search']) :
$_POST['search'];
$search = mysql_real_escape_string($search);
$search = strtoupper(preg_replace('/\s+/', '|',
trim($_POST['search'])));
# create a MySQL REGEXP for the search:
$regexp = "REGEXP '[[:<:]]($search)[[:>:]]'";
$query = "SELECT * FROM `users` WHERE UPPER(`description`) $regexp
OR ".
"`name` $regexp";
$result = mysql_query($query) or die($query . " - " .
mysql_error());
echo "<table>\n";
while($row = mysql_fetch_assoc($result))
{
echo "<tr>";
foreach($row as $key => $value)
{
echo "<td>$value</td>";
}
echo "</tr>\n";
}
}
?>
</body>
</html>
  • 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-10T06:17:24+00:00Added an answer on June 10, 2026 at 6:17 am

    Here’s one option:

    $search = explode(" ", $_POST['search']);
    $description = "";
    $name = "";
    foreach($search AS $s)
    {
        $description .= "`description` LIKE '%".mysql_real_escape_string($s)."%' AND ";
        $name .= "`name` LIKE '%".mysql_real_escape_string($s)."%' AND ";
    }
    
    $description = substr($description, 0, -4);
    $name = substr($name, 0, -4);
    
    $query = "SELECT * FROM `users` WHERE ($description) OR ($name)";
    

    If your search term was something like “Doctor John” your query would look like this:

    SELECT * FROM `users` WHERE (`description` LIKE '%Doctor%' AND `description` LIKE '%John%') OR (`name` LIKE '%Doctor%' AND `name` LIKE '%John%')
    

    which obviously makes BOTH words a requirement in either the description or name field.
    Is this like what you were looking for?

    PS – look into the PDO library for PHP. mysql_ functions are too old to be considered standard anymore. They will work, but you should upgrade.

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

Sidebar

Related Questions

Here's my background: Decent experience with PHP/MySql. Beginner's experience with OOP Why I want
I am a beginner to php and mySQL and I am currently using dreamweaver
Beginner help needed :) I am doign an example form a php book which
I am php beginner and I am trying to make e-commerce by using php.
I am a PHP and MySQL beginner. I am currently doing a top up
I'm no php expert (a mere beginner) but need some help! After hours searching
I am a beginner to PHP and MySQL so please bear with me... I
How can I generate graphs and charts from a mysql database using php? I'm
I want to create my very first web app using HTML, MySQL, PHP and
I am a beginner in web designing (php, mysql). I am creating a classified

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.