prbrowne Posted March 27, 2008 Share Posted March 27, 2008 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!! Link to comment https://forums.phpfreaks.com/topic/98083-help-needed-on-mysql-search-query-with-2-tables/ Share on other sites More sharing options...
ohdang888 Posted March 27, 2008 Share Posted March 27, 2008 $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']; Link to comment https://forums.phpfreaks.com/topic/98083-help-needed-on-mysql-search-query-with-2-tables/#findComment-501837 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.