Forum Topic: Mysql Select Most Similar

(144 views • 2 replies)

This topic is 1 page long.

<< < > >>
None

TitusRevised

Reply To Post Reply & Quote

Posted at: 7/23/06 10:27 PM

TitusRevised LIGHT LEVEL 05

Sign-Up: 02/13/04

Posts: 391

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.


None

TitusRevised

Reply To Post Reply & Quote

Posted at: 7/23/06 10:52 PM

TitusRevised LIGHT LEVEL 05

Sign-Up: 02/13/04

Posts: 391

OR can you search a table with an array, that would give me the same effect...
Example:
<?php
$array_a = array("hello", "my", "name", "is", "bob");
$sql = mysql_query("SELECT * FROM table WHERE field LIKE '$array_a'");
// How do I see if it finds any of the words in the array or something....
?>


None

CronoMan

Reply To Post Reply & Quote

Posted at: 7/25/06 03:05 AM

CronoMan EVIL LEVEL 06

Sign-Up: 07/19/04

Posts: 2,727

At 7/23/06 10:52 PM, TitusRevised wrote: OR can you search a table with an array, that would give me the same effect...
Example:
<?php
$array_a = array("hello", "my", "name", "is", "bob");
$sql = mysql_query("SELECT * FROM table WHERE field LIKE '$array_a'");
// How do I see if it finds any of the words in the array or something....
?>

where field like '%$array_a[0]%' or field like '%$array_a[1]%' or field like '%$array_a[2]' . . . ?
I don't think there is a select most similar in sql, at least afaik

"no sound in ass"


All times are Eastern Standard Time (GMT -5) | Current Time: 08:46 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!