Page 1 of 1

Getting the chunks, dynamic number

Posted: Wed Mar 24, 2004 6:18 pm
by Steveo31
I'm having some probs with a search type form. :(

I have on one page a form with a textbox named "searchterms". On the search.php page (which you upload to) I have:

Code: Select all

<?php

$searchterms = $_POST['searchterms'];
$chunkTerms = explode(" ", $searchterms);

?>
And I'm stuck...hehe...

I need to be able to get the exploded terms into an array or something, so that I can search for them in the DB. For example, the user enters "Joe Smith car". I need PHP to pick out "Joe", "Smith", and "car". I just don't know how to pick them out and put them into an array.

If you have a better method, please share. :)

Posted: Wed Mar 24, 2004 6:21 pm
by markl999
Would it need to search for Joe AND Smith And Car .. or Joe OR Smith OR Car ? ie does the search result need to contain all the terms or any of them?

Posted: Wed Mar 24, 2004 6:29 pm
by magicrobotmonkey
its in an array already!

Posted: Wed Mar 24, 2004 6:41 pm
by John Cartwright
magicrobotmonkey wrote:its in an array already!
Exackly, exploding it puts each variable in an array

$bar="hello my name is johnny";

eg. $foo = explode(" ",$bar);


echo "$bar[0]"; returns hello
echo "$bar[1]"; returns my

etc

Posted: Wed Mar 24, 2004 9:25 pm
by Steveo31
Heh.. ya, I know they are in an array already. I was thinkin of having mySQL search for each individual one, but I wasn't thinking very hard... the OR would be good here.

</airhead>