Author Topic: LIKE makes query ignore other variables  (Read 230 times)

0 Members and 1 Guest are viewing this topic.

Offline AravonaTopic starter

  • Irregular
  • Posts: 2
    • View Profile
LIKE makes query ignore other variables
« on: June 15, 2010, 11:26:08 AM »
I have no access to what mySQL is being used, as I do not host the website myself and my friend has no clue. I believe it to be 5.1

I've got a site which needs to query the database for a search function, currently it uses the following:

Code: [Select]
"SELECT * FROM ver_pro WHERE name LIKE '%$srch2%' OR prCode LIKE '%$srch2%' OR price LIKE '%$srch2%' AND active = '1' AND mID='2' ORDER BY prID"
However the LIKE causes the query to ignore the mID restriction.

I've been trying all day to figure this out to no avail, any help would be greatly appriciated!

Aravona
« Last Edit: June 15, 2010, 11:28:00 AM by Aravona »

Offline Alex

  • Global Moderator
  • Addict
  • *
  • Posts: 2,487
  • Gender: Male
  • < 1 billion
    • View Profile
Re: LIKE makes query ignore other variables
« Reply #1 on: June 15, 2010, 11:37:23 AM »
Try:

Code: [Select]
SELECT * FROM ver_pro WHERE (name LIKE '%$srch2%' OR prCode LIKE '%$srch2%' OR price LIKE '%$srch2%') AND active = '1' AND mID='2' ORDER BY prID
:anim_rules: Read the rules, :rtfm: and don't forget to use [code] / [php] tags!


Offline AravonaTopic starter

  • Irregular
  • Posts: 2
    • View Profile
Re: LIKE makes query ignore other variables
« Reply #2 on: June 15, 2010, 11:51:19 AM »
Thanks, can't believe I didn't pick up on that! I guess I've just been staring at it way too long :)

Offline Alex

  • Global Moderator
  • Addict
  • *
  • Posts: 2,487
  • Gender: Male
  • < 1 billion
    • View Profile
Re: LIKE makes query ignore other variables
« Reply #3 on: June 15, 2010, 12:11:32 PM »
No problem. By the way, can you mark the topic as solved by clicking the button on the bottom left.
:anim_rules: Read the rules, :rtfm: and don't forget to use [code] / [php] tags!