Forum Moderators: open

Message Too Old, No Replies

How do i write this command?

         

Silver420

11:37 am on Sep 30, 2009 (gmt 0)

10+ Year Member



$query = "SELECT * FROM imei WHERE status = '2' ORDER BY id DESC LIMIT 0, 500"

OR

$query = "SELECT * FROM imei WHERE status=2 ORDER BY id DESC LIMIT 0, 500"

I have tried both, and im sure im still doing something wrong. Ive read for numerical values it should be the second one though thought id try to get some confirmation

LifeinAsia

3:16 pm on Sep 30, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Yes, the second one is correct if ID is a numeric value. Use single quotes for CHAR & VARCHAR values.

What error are you getting?

rocknbil

7:44 pm on Sep 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ive read for numerical values it should be the second one though thought id try to get some confirmation

Either should work (in mySQL, not sure about other database types.) You can quote queries on numeric fields but it is not required. IMO the confusion comes from working with PHP: when quoted, a variable's value is cast as a string type, without quotes, a numeric type - but this is in PHP, not mySQL. mySQL statements in PHP are still mySQL statements, and the select on a numeric field is still optional.

So if you're looping though a set of values in building a complex select, you need not make an exception to remove quotes on numeric fields. The two you posted should yield identical results.