Jump to content

PHP multiple db search


rwslippey

Recommended Posts

Okay first is first I appreciate any help that is given. I've really torn my hair out over this one.

 

I have two databases with the same exact structure, however different data.

 

They can not be linked as the data in one table does not relate at all to the other table.

 

 

I need to be able to search table1 then table 2 and be able to echo any results that come back from either table.

 

hope someone can help. I have all of the search scrips written to search and search one table fine, just teaching a new trick isn't working.

 

again thanks for the help.

Link to comment
https://forums.phpfreaks.com/topic/154731-php-multiple-db-search/
Share on other sites

Something like this maybe:

 

SELECT `fields` FROM `database1.table` WHERE  `database1.table.searchfield` = ? UNION SELECT `fields` FROM `database2.table` WHERE  `database2.table.searchfield` = ?

 

Note that the select field count needs to be the same on each side of the UNION.

Iv been trying to use something like

 

select * From tbl1,tbl2 where tbl1.field LIKE $search OR tbl2.field LIKE $search

 

I think the problem is in the PHP  and what it is displaying. I need it to display the results from either table... so If it gets results from either table is displays results from both tables.. and if it gets multiple results from either table it'll display them also... basicly a keyword search I guess is the way to explain it...

 

 

Okay,

 

 

found the problem.... The query you sent me worked in phpmyadmin so I got into looking at the code...

 

My add stored the record id in a variable...  and then deleted duplicates... so the second record was never displayed (some idiot made the two tables with the same record id's  go figure... that'd be me)

 

thanks for your help

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.