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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.