simple question,hard solution

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
sebs
Forum Commoner
Posts: 97
Joined: Tue Sep 20, 2005 10:13 am

simple question,hard solution

Post 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.
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

Post by mickd »

Code: Select all

SELECT * FROM database WHERE field LIKE '%$search%'
something like that should do it.
sebs
Forum Commoner
Posts: 97
Joined: Tue Sep 20, 2005 10:13 am

Post by sebs »

I said ONLY for NEW JERSEY or JETS.What you gave me works also for NE,JE,.....
Thanks anyway.
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..)
Post Reply