cosmicsea Posted December 20, 2010 Share Posted December 20, 2010 I am currently using this select keyword from ".$mysql_table_prefix."keywords WHERE keyword like '%{$query}%' LIMIT 5 to show 5 related keywords to searches done on my search engine. but I also want to query the table query_log and the query column for results, so I need something like this. select keywords.keyword, query_log.query from ".$mysql_table_prefix."keywords, query_log WHERE keyword and query like '%{$query}%' LIMIT 5 I know that does not work but I wanted to show some kind of example of what I am trying to do. how can I get the info from both tables? and is there anything I could add to have more relevant related keyword results if more than 5 exist? Like if I use order by something "something being any sql attribute" can I achieve better results? can anyone help me with this? thanks. Link to comment https://forums.phpfreaks.com/topic/222189-querying-multiple-tables/ Share on other sites More sharing options...
cosmicsea Posted December 22, 2010 Author Share Posted December 22, 2010 Does anybody know how I can turn both of these into 1 query? $result=mysql_query("select keyword from ".$mysql_table_prefix."keywords WHERE keyword like '%{$query}%' LIMIT 3"); $result=mysql_query("select query from ".$mysql_table_prefix."query_log WHERE query like '%{$query}%' LIMIT 3"); Both of those work fine but I need to make it a single query. Can someone please help? Link to comment https://forums.phpfreaks.com/topic/222189-querying-multiple-tables/#findComment-1150129 Share on other sites More sharing options...
tomindo Posted December 22, 2010 Share Posted December 22, 2010 you need to explode() function to convert queries into array, then use foreach loop Link to comment https://forums.phpfreaks.com/topic/222189-querying-multiple-tables/#findComment-1150205 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.