Start by showing us the *ACTUAL* query used.
That is, get rid of all the PHP variables in there and show us the query that is actually being passed to MySQL.
And show use the *ACTUAL* output from the query, *NOT* whatever your PHP code is doing to it.
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.