tags:

views:

44

answers:

1

Hello!

The table name is 'pages'..

I need to make a search function, where I can submit the field $_POST['search']['s_value'] and check if it is LIKE the fields 'emne' or 'tekst'..

But in that matter I would also like, that my query is ordering by the percentage of matching.. So if I'm searching for "car rental" and I have a page which say "car rental has been easier over the past years" it is 100%.

If it is possible, I would also like the search to make a 'teaser' with the first match of the text, where it is highlighted in a div with the class='search_highligthed_text' ..

Is that in any way possible to create???

A: 

Sorry, i cannot undertand the problem with similar_text(); why don't you just put data in an array an than sort them?

ArtoAle
OP is looking for a way to select MySQL results based on similarity; `similar_text()` is a PHP function and can only be applied _after_ you've retrieved the data. If OP wants to display _all_ the data, you can use the PHP function, but I'm betting he only wants to retrieve e.g. everything that's a 90 to 100% match.
Alec
No I actually just want to page them - with 15 hits pr. page sorted by the percentage of similarity (desc)..
Dennis Lauritzen
In this case you can do it with PHP. Put your data in a session array (if you use a framework eg ZendFramework there sould be better way to manipulate session), sort it and the trick is done!
ArtoAle
I have made it work with some arrays - if you want to see the solution, then try and write me.
Dennis Lauritzen