0

How can I query a database using the results of a prior query if they are in array? Below is what I have thus far.

$query = "SELECT * from searchtestdb where engname in ( SELECT synonyms.synonym  FROM words  LEFT JOIN synonyms ON synonyms.word_id = words.word_id WHERE word LIKE '%$searchBox%') ";

while($result = mysql_fetch_array($query)) 
        {
            echo $result['engname'];
            echo "<br> ";
            echo "<br> ";
        }

How can I get the $result['engname'] and query again? I'm thinking something like

SELECT * from searchtestdb where engname LIKE '%$result['engname']%';

but that obviously doesn't work. Any ideas?

2

1 Answer 1

2
while($result = mysql_fetch_array($query)) 
{
   $query2 = "SELECT * from searchtestdb where engname LIKE '%".$result['engname']."%';";
   $result2 = mysql_query($query2);
   while($row = mysql_fetch_array($result2)) 
   {
       echo $row["somthing"];
   }
}
Sign up to request clarification or add additional context in comments.

1 Comment

good answer but i think some more explanation about concating strings is in order: For more info read this: php.net/manual/en/language.operators.string.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.