RE: [PHP-DB] populating <select> and searching to criteria
| From: | Shannon Doyle | Date: | Tue, 28 Oct 2003 04:34:34 +0000 |
| Subject: | RE: [PHP-DB] populating <select> and searching to criteria | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-31323@lists.php.net to get a copy of this message | ||
Thanks Micah,
while ($d = mysql_fetch_assoc($return)) {
?><option
value="<?=$d['value']?>"><?=$d['name']?></option>
----- I get
a parse error on this line.
while ($d = mysql_fetch_assoc($return)) {
?><option value="<?=$d['value']?>"<?
if ($other_table_value == $d['value'])
echo " selected";
?>><?=$d['name']?></option>
<?
}
Ok cool, I am assuming that this will be OK once I work out the parse
error on the above option.
> Third:
> If you're using MySQL, check this out:
> http://www.mysql.com/doc/en/Fulltext_Search.html
> If you're using something else, it's more complex I think. Someone may
> have an
> elegant solution, but I would do something like:
// Get total number of keywords:
$numofkeywords = count(str_replace ( " ", " ", $keywords));
// Split up your search words:
$search = explode(" ", $keywords);
$total_matched = 0;
// loop through the array of search terms and get number of returns.
foreach ($search as $searchword) {
$total_matched += count(str_replace($searchword, $searchword,
$keywords));
}
// echo out the result in percent. (to one decimal place even!)
echo "Percent Matched: ".round(($total_matched/$numofkeywords)*100),
1)." %";
This only partly resolves my problem, I am not looking for a word count,
I am looking to return those records that have one or more of the
keywords in them, and display a percentage result next to each record
that matches.