Jump to content

Recommended Posts

I have 2 fields, Keywords & Type. I have to search from 2 different tables knb_faq & knb_solution as per the keywords & type.

Here is my mysql query :

 

$keyword=$_GET['keyword'];
$type=$_GET['type'];
$srch=mysql_query("select knb_faq.*,knb_solution.* from knb_faq,knb_solution where (knb_faq.solution LIKE '%$keyword%' or knb_faq.keywords LIKE '%$keyword%' or knb_faq.subject LIKE '%$keyword%'and knb_faq.type='$type') or
(knb_solution.solution LIKE '%$keyword%' or knb_solution.keywords LIKE '%$keyword%' or knb_faq.solution LIKE '%$keyword%' and knb_solution.type='$type')") or die (mysql_error());

 

There is no error msg but my problem is that for this query I am not getting result perfectly. The search is occured but it is not searching from both the tables according to Keyword & Type.

Is there any wrong in the sql query? If so, Please tell me the right syntax.

Link to comment
https://forums.phpfreaks.com/topic/157667-search-from-different-tables/
Share on other sites

Hi

 

First thing I notice is that you are basically joining 2 tables without any join conditions. As such you are first of all bringing back every single combination of records from the 2 tables.

 

Either add a join condition, or select from each table seperatly and UNION the results.

 

All the best

 

Keith

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.