Jump to content

Archived

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

TitusRevised

PHP/MySQL SELECT most similar (help me)

Recommended Posts

Is there an sql function to SELECT any rows in a table most similar to a field... like instead of SELECT * FROM table WHERE field LIKE '%$string%' which finds a row with keyword $string, so if $string is "hi my name is" but there isnt a row like but there is a row "hello my name is" it would pull that row because its most similar.

PHP example:
<?php
$string = trim(strip_tags(addslashes($_POST['usermsg'])));
$sql = mysql_query("SELECT * FROM table WHERE field = '%$string%");
// This finds me a row where field "field" has the $string in it exactly somewhere
?>
How can I make it so that if it's not exact it pulls out the row with the field "field" most similar to $string?

Your great wisdom and intelligence on the matter to assist me is appreciated greatly.

Share this post


Link to post
Share on other sites
is this a text search?

Share this post


Link to post
Share on other sites
[quote author=hvle link=topic=101617.msg402305#msg402305 date=1153710195]
is this a text search?
[/quote]
yes, $string is a string...text

Share this post


Link to post
Share on other sites
you might want to look at "match .. against()" in mysql manual

Share this post


Link to post
Share on other sites
Yes, you can use full-text searching. If, this is manditory, you're able to add a fulltext index on the column you want to search.

Share this post


Link to post
Share on other sites

×

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.