Ajpalma Posted May 11, 2008 Share Posted May 11, 2008 I have a query that has a selectable ranges letting user select the top and bottom values and it finds the entries between them using greater than and less than for a value, say 350,000 the top value of 900,000 and bottom of 100,000 will return the correct value. but a top value of 2,000,000 or a bottom value of 50,000 will return NOTHING. does anyone know why it does this?or a solution? $result = mysql_query("SELECT * FROM deals WHERE price >= '$sql2' AND price <= '$sql1' ") thanks, Alex Quote Link to comment Share on other sites More sharing options...
mezise Posted May 11, 2008 Share Posted May 11, 2008 Hi, everyting is logically correct. Display query before it is executed and check the syntax. Maybe there is a space between thousand and million part of 2 ,000,000 price? Quote Link to comment Share on other sites More sharing options...
Ajpalma Posted May 11, 2008 Author Share Posted May 11, 2008 nah, it doesn't return the right value even with 50,000 as the bottom limit(even with a 6 digit top limit) it just seems like it only works when both limits are 6 digits Quote Link to comment Share on other sites More sharing options...
mezise Posted May 11, 2008 Share Posted May 11, 2008 Debug PHP code and post here the result of variable $displayQuery for problematic range. $displayQuery = "SELECT * FROM deals WHERE price >= '$sql2' AND price <= '$sql1' "; print_r($displayQuery); $result = mysql_query($displayQuery); Quote Link to comment Share on other sites More sharing options...
Ajpalma Posted May 11, 2008 Author Share Posted May 11, 2008 SELECT * FROM deals WHERE price >= '50,000' AND price <= '2,000,000' is the result Quote Link to comment Share on other sites More sharing options...
mezise Posted May 11, 2008 Share Posted May 11, 2008 The comma character might be the problem. Maybe it is configurable in MySQL but I always use default format of numbers: e.g. 1222333 for INT type and 1222333.44 for DOUBLE type. So change the code into this: $displayQuery = "SELECT * FROM deals WHERE" . " price >= '" . preg_replace('/([^0-9])/i', '', $sql2) . "'" . " AND price <= '" . preg_replace('/([^0-9])/i', '', $sql1) . "' "; $result = mysql_query($displayQuery); Quote Link to comment Share on other sites More sharing options...
Ajpalma Posted May 11, 2008 Author Share Posted May 11, 2008 That was it, Thank you VERY much Quote Link to comment Share on other sites More sharing options...
fenway Posted May 12, 2008 Share Posted May 12, 2008 What a mess.... store integers as INT. Quote Link to comment Share on other sites More sharing options...
mezise Posted May 12, 2008 Share Posted May 12, 2008 What a mess.... store integers as INT. He does. The problem was with not cleaning the data sent from web interface (separation signs). Quote Link to comment Share on other sites More sharing options...
fenway Posted May 13, 2008 Share Posted May 13, 2008 What a mess.... store integers as INT. He does. The problem was with not cleaning the data sent from web interface (separation signs). So he's NOT... integers don't have non-digit characters. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.