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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:46:30+00:00 2026-05-28T13:46:30+00:00

In my web application I am planning to include a Search field which will

  • 0

In my web application I am planning to include a Search field which will allow users to enter a string.

This string will then be used to compare against rows of data in multiple tables for example in this database. (this is just an example, in the real problem there is about 20 tables).

Table List:

  • Customer
  • Books
  • Paintings

What is the best way to do a search, as this is my first time doing one that would look over multiple tables?

Do you just go through the tables sequentially comparing each row to the search string or can you make a query that searches the whole database in general?

Should you stop the search once you found a exact match or do you just continue the search regardless if you found a match? Incase there are multiple rows of the same type?

I would like to do this in the most “correct” way possible I had a look at some examples but they only seem to relate to one or two table searches.

I have this pseudo code in my head for what I might do so if you could give me feedback on that too

Get string from $_POST['search'] 
Strip string of special characters that could be used for Mysql injection.
Connect to db 
Search first table for row that is LIKE string
If match found then add to result object
Search next table, and repeat.
When finished search disconnect from DB.

So I hope you lot will be able to guide me link to materials so I can implement this piece of functionality as best as possible.

Thankyou 🙂

  • 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-28T13:46:30+00:00Added an answer on May 28, 2026 at 1:46 pm

    First of all, let you know that this will become in an very poor performance search if search condition is ‘contains’ but not starts with. Also that indexes are needed for all searchables columns.

    Whell, the most easy way to do this query is to make a big view with an union of all search fields:

    create view my_search as (
       select 
         id_customer as key, 
         customer_name as value, 
         'customers' as table,
         1 as priority
       from customer
       UNION ALL
       select 
         id_customer as key, 
         customer_alternate_name as value, 
         'customers' as table,
         2 as priority
       from customer
       UNION ALL
       ...
       UNION ALL
       select 
         id_Paintings as key, 
         Paintings_name as value, 
         'Paintings' as table,
         8 as priority
       from Paintings
    )
    

    Then perform query over view:

    select * from my_search
     where value like ...
     order by priority 
    

    Notice that this don’t solve your requeriment to get results only from first table where string appears, you can stop php fetching rows when priority change is found.

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

Sidebar

Related Questions

I am planning on developing .NET web application which also will be accessed from
I am planning to develop a small web application, which enable users to create
I'm planning to develop a web application which will have many static pages (about,
I'm planning to write gateway web application, which would need terminal window with VT100/ANSI
I'm planning to develop a web application that targets the iPhone. I will use
I'm planning to write a web application (.net probably) that will need to analyze
I am planning on writing a medium size web application that will be XML
I was planning to create an unordered list of users of my web application
We're planning to create a web application where users can build custom forms, choosing
I'm planning on writing a spine/backbone.js style web application which basically just transfers a

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.