multiple keyword search

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
scotchgitt
Forum Newbie
Posts: 2
Joined: Wed Oct 22, 2003 2:24 pm

multiple keyword search

Post by scotchgitt »

I am fairly new to PHP but have created numerous web databases in other languages for my employer.

I am branching out and teaching myself PHP and MySQL.

so far I have created a simple web database (add, list, search and edit) that searches for a keyword in multiple fields BUT what I now want is to enter multipe words in the same field and have teh server run these words through multiple fields.

I take it I need to parse the days and then run the search for each independantly....any pointers where to begin?

Thanks
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post by scorphus »

Not sure if I got it rigth, but try something like this:

Code: Select all

<?php
function runEachWordThroughMultipleFields ($keyword) {
	// Yoy do your job here...
	echo 'running ', $keyword, "...\n"; // print the keyword for example purposes
	return;
}

$multipleWords = "word1 word2 word3 word4"; // separated by space ' '
$keywords = explode(' ', $multipleWords); // [url=http://www.php.net/explode]explode info[/url]
foreach ($keywords as $value) { // [url=http://www.php.net/foreach]foreach info[/url]
	// run a function:
	runEachWordThroughMultipleFields($value);
	// or/and do other things...
}
?>
The output:

Code: Select all

running word1...
running word2...
running word3...
running word4...
Note this code won't solve your problem but it is a way to show you how you can handle it...

Hope that helps... let us know if it doesn't ;)

Cheers,
Scorphus.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

I take it you want to do a phrase search?

"... WHERE column RLIKE '[[:<:]]" . $phrase . "[[:>:]]'";

If you only need to support mysql v4.01+, also check out fulltext search and MATCH.
Post Reply