Mysql -> not including results where column contains â€

I have created a sql query to seach for the max value of a column but in my column i have a result which is —

i thought i had done the code so that it omitted this value from the results but this does not seem the case.

SELECT MAX(`OR`) AS bear FROM horsesrp WHERE  `horse` =  '".$horse."' AND `class` NOT LIKE '%â€%' and `Class` LIKE  '%".trim($class)."%' and Place = '1' or  `horse` =  '".$horse."' AND  `Class` LIKE  '%".trim($class)."%' and Place = '2' ORDER BY  `OR`"

Open in new window

Can anyone help at all?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Walter RitzelSenior Software EngineerCommented:
Have you  tested the query itself previously in phpmysqladmin or something like that? Because my first thought would be check if you dont need some parenthesis to group the logical expressions correctly.
Ray PaseurCommented:
It looks like you have a character-encoding collision.  This is an increasingly common issue for PHP users because PHP has changed the way character encoding works recently.  This article tells what's happening and what you must do to correct the situation.

If you just want the TL;DR version, ensure that your character encoding is consistent all the way through the process from the moment of data creation, to the storage in the data base, to the retrieval, and to the display in the HTML document.  Any mixups along the way and you'll get unwanted characters of some sort in the output.  And if you want to future-proof your code, choose UTF-8 throughout.
Since there are duplicated conditions, I assume you need to separate the two sets of filtering conditions at "OR".
You can try with Locate & Hex representation of "â€", to find out whether you have Unicode issue or something else:
FROM horsesrp
(`horse` =  '".$horse."' AND
/*  `class` NOT LIKE '%â€%' and   */
LOCATE(UNHEX('C3A2E282AC'), `class`) = 0 and     /* Note: Locate becomes case-sensitive if your column is binary string  */
`Class` LIKE  '%".trim($class)."%' and
Place = '1') 


(`horse` =  '".$horse."' AND
`Class` LIKE  '%".trim($class)."%' and
Place = '2')


Open in new window

I just used "Select HEX('â€')", to get 'C3A2E282AC' that I used in the above query.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.