Jump to content

Help needed on MySQL search query with 2 tables


prbrowne

Recommended Posts

Hi

 

I have two tables as follows:

 

table 'question' with fields 'patient_id', 'answer_id' and 'terms', and

 

table 'answer' with fields 'answer_id' and 'answer_path'.

 

I need to search question.terms for a keyword match and then join that match to the corresponding foreign key (answer_id) in table answer to return 'answer_path'.

 

Any ideas on this greatly appreciated!! ;D

$result = mysql_query("SELECT `answer_id` FROM `question` WHERE `terms` LIKE '%$key_word%' ")or die(mysql_error());

$row = mysql_fetch_array($result);

 

$a_id = $row['answer_id'];

 

$result = mysql_query("SELECT `answer_path` FROM `answer` WHERE `answer_id` = '$a_id' ")or die(mysql_error());

$row = mysql_fetch_array($result);

 

echo $row['answer_path'];

 

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.