Page 1 of 1
simple question,hard solution
Posted: Thu Oct 06, 2005 8:10 am
by sebs
A simple question that has created me many problems:
If I have "New-Jersey Nets" for example how can I make the query select this field only if it is entered(or compared with ) "New" or "Jersey" or "Nets".I have seen some similar solutions but one worked.
Posted: Thu Oct 06, 2005 8:13 am
by mickd
Code: Select all
SELECT * FROM database WHERE field LIKE '%$search%'
something like that should do it.
Posted: Thu Oct 06, 2005 8:18 am
by sebs
I said ONLY for NEW JERSEY or JETS.What you gave me works also for NE,JE,.....
Thanks anyway.
Posted: Thu Oct 06, 2005 8:51 am
by mickd
im sure there will be an easier way then what im saying below because its very impractical
Code: Select all
$result = mysql_query("SELECT * FROM database");
$row = mysql_fetch_array($result);
foreach($row as $var) {
$split = preg_split('/(" "|-|_)/', $var); // i dont know how to write regular expressions (supposed to split at space, underscore and dash)
$num = count($split);
for($i=0; $i < $num; $i++) {
if($search == $split[$i]) {
echo $var . ' match found\n';
continue;
}
}
}
have you ever seen something more impractical
not sure if itll work, just made it up.
Posted: Thu Oct 06, 2005 8:55 am
by feyd
matching full words only for words in your query can be done via the REGEXP command MySQL has (not sure if it's in other DBMS' I imagine it would in some form..)