Noah Yamen
Noah Yamen

Reputation: 137

PHP/MYSQL: less than or equal to 50 is displaying records in the hundreds?

Heres the query I am using:

SELECT * FROM inventory WHERE status='live' and price<='50' ORDER BY id DESC;

It is showing all items under $50. But then it also shows all items over $100? I'm guessing this issue has something to do with these prices being triple digits. Other thing to mention is that the prices also include .00 after their price.

Any pointers?

Upvotes: 0

Views: 4080

Answers (2)

Pete B.
Pete B.

Reputation: 3286

I think the problem is that you have 50 in quotes. MySql is probably treating it like a string.

... AND price <= 50 ORDER BY ....

Upvotes: 1

J.D. Pace
J.D. Pace

Reputation: 616

If the price column datatype is "CHAR" (string), "100", and "49999" are both <= "50". Change one or both data types (columns and comparison) to DECIMAL(10,2) or another numeric type.

Upvotes: 0

Related Questions