Getting the chunks, dynamic number

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Getting the chunks, dynamic number

Post 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. :)
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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?
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

its in an array already!
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post 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>
Post Reply