Page 1 of 1

multiple keyword search

Posted: Wed Oct 22, 2003 2:24 pm
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

Posted: Wed Oct 22, 2003 3:13 pm
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.

Posted: Wed Oct 22, 2003 6:17 pm
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.