Jump to content

Search multiple mySQL tables for search function


petenaylor

Recommended Posts

Hi all

 

How do I modify the below code to search multiple tables in mySQL database?

 

$query = "select * from store_items where description like \"%$trimmed%\"  or title like \"%$trimmed%\" or dimensions like \"%$trimmed%\" order by id ASC";

 

$numresults=mysql_query($query);

$numrows=mysql_num_rows($numresults);

 

It is for a search function and I need it to search another table called 'about_text' and 'faq_text'

 

Thanks

Pete

Link to comment
Share on other sites

IN that case we need to use union. Like,

 

select * from store_items where description like \"%$trimmed%\"  or title like \"%$trimmed%\" or dimensions like \"%$trimmed%\" order by id ASC

 

union

 

select * from about_text where description like \"%$trimmed%\"  or title like \"%$trimmed%\" or dimensions like \"%$trimmed%\" order by id ASC

 

union

 

select * from faq_text where description like \"%$trimmed%\"  or title like \"%$trimmed%\" or dimensions like \"%$trimmed%\" order by id ASC

 

here the condition is first query's fields = 2nd query's fields = 3rd queries field

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.