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

Dude,

 

Need to know whether these three tables are related to each other. If its related tables then we'l b using joins. If these are not related, need to know the field names in each tables to write query with union functionality........

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.