Jump to content

[SOLVED] Query with greater than and less than


Ajpalma

Recommended Posts

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

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);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.