• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 281
  • Last Modified:

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?
0
runnerjp2005
Asked:
runnerjp2005
1 Solution
 
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.
0
 
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.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11880-Unicode-PHP-and-Character-Collisions.html

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.
0
 
jimyXCommented:
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:
SELECT MAX(`OR`) AS bear
FROM horsesrp
WHERE
(`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') 

OR

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

ORDER BY  `OR`

Open in new window


PS:
I just used "Select HEX('â€')", to get 'C3A2E282AC' that I used in the above query.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now