Re: Association Problem?
| From: | Gabe | Date: | Mon, 21 Jun 2004 20:55:38 +0000 |
| Subject: | Re: Association Problem? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-188777@lists.php.net to get a copy of this message | ||
Thanks for all the help guys! All of your suggestions got me going in the right direction. I'm using ADOdb, so some of the code below may look a little different than suggested.
//stores the RS in an array and creates a sortable array for relevancy
while ( !$objRS_Results->EOF )
{
$strHaystack = $objRS_Results->fields[1] . $objRS_Results->fields[2];
$intRelevancy = substr_count( $strHaystack, $strCriteria );
$arrRS_Data[$objRS_Results->fields[0]] = array( "title" => $objRS_Results->fields[1], "relevancy" => $intRelevancy );
$arrSort[$objRS_Results->fields[0]] = $intRelevancy;
$objRS_Results->moveNext();
}
//prints out the search results based on the relevancy array
while ( current( $arrSort ) )
{
echo $arrRS_Data[key($arrSort)]["title"] . "<br />";
next( $arrSort );
}
Thanks again
Gabe
Gabe wrote:
Wanted to see if anyone had any input on this. I have a recordset that is returned to me in my script. What I then would like to do is go through each row of the recordset and use the substr_count function to count the number of times a string appears in each row. Then I'd like to sort & display the recordset based on how many times the string appeared in each row. Basically this is a very light search with a very quick & dirty way to find relevancy. I've thought that I could just store the relevancy numbers in an array, but then how do I know which relevancy number goes with what row in the recordset? That's the association problem I'm talking about. Also, how would I then sort the recordset accordingly based on the relevancy array? I've been looking through the PHP documentation and can't quite get past this question. Anyone have any ideas? Thanks! Gabe