rwslippey Posted April 19, 2009 Share Posted April 19, 2009 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 More sharing options...
soak Posted April 19, 2009 Share Posted April 19, 2009 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. Link to comment https://forums.phpfreaks.com/topic/154731-php-multiple-db-search/#findComment-813658 Share on other sites More sharing options...
rwslippey Posted April 19, 2009 Author Share Posted April 19, 2009 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... Link to comment https://forums.phpfreaks.com/topic/154731-php-multiple-db-search/#findComment-813661 Share on other sites More sharing options...
soak Posted April 19, 2009 Share Posted April 19, 2009 So you have two tables, not two databases? select * From tbl1 where tbl1.field LIKE $search UNION select * From tbl2 where tbl2.field LIKE $search Link to comment https://forums.phpfreaks.com/topic/154731-php-multiple-db-search/#findComment-813665 Share on other sites More sharing options...
rwslippey Posted April 19, 2009 Author Share Posted April 19, 2009 yes that is correct. Sorry about that... I said two databases Link to comment https://forums.phpfreaks.com/topic/154731-php-multiple-db-search/#findComment-813667 Share on other sites More sharing options...
rwslippey Posted April 19, 2009 Author Share Posted April 19, 2009 Okay, got it to return a result however it's still returning just one... like I said earlier I think it's in the php code.... Link to comment https://forums.phpfreaks.com/topic/154731-php-multiple-db-search/#findComment-813676 Share on other sites More sharing options...
soak Posted April 19, 2009 Share Posted April 19, 2009 Can you post the relevant code then? Link to comment https://forums.phpfreaks.com/topic/154731-php-multiple-db-search/#findComment-813679 Share on other sites More sharing options...
rwslippey Posted April 19, 2009 Author Share Posted April 19, 2009 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 Link to comment https://forums.phpfreaks.com/topic/154731-php-multiple-db-search/#findComment-813680 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.