Hello, I wanted to know how to do the following using PHP and MySQL. Basically I want to break up a string into single words and put them into an array. Then, I want to cycle through each word in that array and run a MySQL query using that word. Then after I have run a query for every word in that initial array, I want to compare them using array_intersect and finally echo out the records that all the arrays had in common. I just cannot get my head wrapped around working with these arrays. Any help would be great! Thanks in advanced!
to break string into array or single words use $arr=explode(" ",$str); PHP: then to loop through the array use foreach($arr as $word) { //put here the mysql query you need to make //you can use $word to make up your query as required } PHP: hope I could help
Excellent! but how would I store the SQL results into individual arrays, so that I can compare the contents at the end?
You could probably do something like this: <?php $str = ("test1 test2 test3 test4 test5"); $arr = explode(" ",$str); $result = array(); foreach ($arr as $word) { $result[] = $word; } print_r($result); ?> PHP: note, this is pseudocode, and you would have to modify it to add the queries and add the result of the queries to the result-array. It should be a starting point, though.