intrik Posted September 20, 2006 Share Posted September 20, 2006 Hey guys, I made this code to count how many times the search string occurs in the results data[code]$desc_lower = strtolower($results['desc']);$title_lower = strtolower($results['title']);$desc_count = substr_count($desc_lower, $searched);$title_count = substr_count($title_lower, $searched);$count_searches = ($title_count+$desc_count);echo $count_searches;[/code]Idealisticly what I'd like to do is order the sql results by the frequency of the occurance, so obviously if $count_searches had a value of 1234 it would order before a value of 1233.So you get the most relevant search results at the top.Any ideas? Quote Link to comment Share on other sites More sharing options...
fenway Posted September 20, 2006 Share Posted September 20, 2006 I'm confused.. if you're doing this type of "scoring" in PHP, why not sort the results in PHP? Quote Link to comment Share on other sites More sharing options...
intrik Posted September 20, 2006 Author Share Posted September 20, 2006 Well, the problem is that I can't SORT BY relevance DESCIn my version of MySQL... So it's going to have to be done with some PHP, how do I sort the results in PHP? Any ideas? I didn't even know you could do that... Quote Link to comment Share on other sites More sharing options...
fenway Posted September 21, 2006 Share Posted September 21, 2006 I assume that you can write a custom sort routine, though I never have in PHP. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.