floating point - PHP not parsing 1000, 10000, 100000, etc. **Fixed** -


i using following code take html $_post vars [type:text] representing min & max price, sanitize , strip "$" , ",", commit them $_session , use them mysql query against data in column of type "float". code follows...

//the locale i'm using setlocale(lc_all, 'en_us.utf8');   //the minimum price handled //sanitized post var session var $_session['minprice'] = filter_var($_post['minprice'], filter_sanitize_stripped);  // strip currency symbol , commas $_session['minprice'] = str_replace(array(',','$'),array('',''),$_session['minprice']);  //session var local float var sql query $minprice = floatval($_session['minprice']);   //the same done maximum price //sanitized post var session var $_session['maxprice'] = filter_var($_post['maxprice'], filter_sanitize_stripped);  // strip currency symbol , commas $_session['maxprice'] = str_replace(array(',','$'),array('',''),$_session['maxprice']);  //session var local float var sql query $maxprice = floatval($_session['maxprice']);   //the sql query $sql = 'select * tablename '; $sql .= "zip '$searchzip%' "; //ignore $sql .= "&& sellprice >= '$minprice' "; $sql .= "&& sellprice <= '$maxprice' "; $sql .= "order id desc"; 

$minprice , $maxprice compared value mysql table , result handled accordingly, $minprice <= $sellprice <= $maxprice.

for variable $sellprice = 12.01, following search queries return rows mysql database:

the following returns rows wonderfully.
($minprice, $maxprice)
0, 13
0.00, 13.00
$0.00, $13.00
$10.00, $12.02
$0.00, $12111
$0.00, $82711

the following not return rows, don't know why.
($minprice, $maxprice)
0, 100
0, 1000 - 1000000 , beyond
0, 1,000 - 1,000,000 , beyond
0, 111 // thought issue 0's or commas being parsed incorrectly
$0.00, $111 - $111111 , beyond
10, 11112 //note 12111 returns rows above

i must missing here, fundamental , silly. appreciate people willing give, thank you.

if you'd take @ site url http://listing.dyndns.org, it's nothing special it's beginner's project.

edit0: there 1 listing on there currently, search in 99208 zip code.

edit1: used expression 'select id tablename sellprice >= 0 && sellprice <= 111111.11;' , returned right rows, know data in database ok. must php.

edit2: looks numbers before first comma or decimal being evaluated against what's in database. lost.

fixed: read great post on here badness ensues when stories monetary values in float column rather decimal column. changed column type decimal(9,2) , cast php variables explicitly using (int). values stored , doing comparison operations against database values works great. hope useful someone.

setlocale under php 5.3 deprecated , has no effect when returns false!


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -