Jump to content


MySQL Like Statement


3 replies to this topic

#1 Tirus

    P2L Jedi

  • Members
  • PipPipPip
  • 764 posts
  • Gender:Male
  • Location:Montreal, Canada
  • Interests:Web Design, Programming, Music, Martial Arts

Posted 28 September 2006 - 04:55 PM

hello everybody,

I have a mysql query which is used to search through business listings and turn up results, depending on the business name and state the user wants to search for. I have " where Bname like '%"&strBusiness&"%'" " in my query (its asp) to ensure that I get all business names similar to that entered by the person to show up.

Here are a couple of examples of what is happening:

If the person types Univer into the business name, among those that show up, Universal Paragon Corporation will too.
But, if the person types in Universal, the only 2 businesses that show up are ones called Universal. but Universal Paragon Corporation does not show up.

Now if I have the % on the beginning and at the end of my business string, shouldn't whatever was typed be matched up with any listing that has what was typed somewhere within it.

To make things even more weird, if you type in Universal%, Universal Paragon Corporation does in fact come up...now why should the person entering the business name have to manually add % at the end of the business name...it makes no sense.

Any and all help would be greatly appreciated.

Edited by Tirus, 28 September 2006 - 04:56 PM.


#2 Tirus

    P2L Jedi

  • Members
  • PipPipPip
  • 764 posts
  • Gender:Male
  • Location:Montreal, Canada
  • Interests:Web Design, Programming, Music, Martial Arts

Posted 03 October 2006 - 04:19 PM

i still haven't figured out what the problem is...anyone have any ideas? if it's the asp that is intimidating some of you from responding, then just assume it is PHP and think of why a like statement would return results this way.

Basically, why would the search for words LIKE %Universal% not include "Universal Paragon Corporation" as a result and only include results exactly with the words "Universal".

Any and all help would be greatly appreciated.

Edited by Tirus, 03 October 2006 - 04:19 PM.


#3 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 03 October 2006 - 08:46 PM

I had a problem something like this once, so I went and used a regex match.

$result = mysql_query("SELECT * FROM `table` WHERE `Bname` RLIKE '$query'") or die(mysql_error());

That's PHP, so I hope you can translate that to ASP, lol.

(RLIKE is a synonym for REGEX. ;))

#4 Tirus

    P2L Jedi

  • Members
  • PipPipPip
  • 764 posts
  • Gender:Male
  • Location:Montreal, Canada
  • Interests:Web Design, Programming, Music, Martial Arts

Posted 03 October 2006 - 09:43 PM

ok, I did some research with what you mentioned...using RLIKE instead of LIKE and I got some good answers for PHP ;) ;) :( , just messing around with it to try and get it to go with ASP.

I am referring to this link for PHP:


http://www.sitepoint...ogy-3-php-mysql

SELECT * FROM articles WHERE title RLIKE '^How '

The above statement also selects every article in which the title begins with "How" followed by a space.

I am trying to get that to work with:

and Bname like '%"&strBusiness&"%'"

so maybe someone can take a while guess. For all you php'ers, my "&strBusiness&" is the same as Demonslay's $query so no big deal with the coding difference.

I have already tried:

and Bname rlike '^"&strBusiness&"%'"

and Bname rlike '^"&strBusiness&"%'"

and Bname rlike '%&strBusiness&" %'"

and some other stuff similar to that.

I will keep looking through google searches to see what I can come up with but if anyone has any ideas, throw them my way.

Tirus


NEW EDIT:

Problem NOT fixed, my temp fix did work as it screwed up the search when it was being done for a phone number...now back to square 1. :(

Edited by Tirus, 05 October 2006 - 04:25 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users