Jump to content

Sort SQL Results by count of string occurance?


intrik

Recommended Posts

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.