PHP mySQL Query ignores decimal values -
i'm using ajax pull stocks database based on values contained on input. 1 of these values average returns, contains decimal value.
i have 2 variables, $min_returns
, $max_returns
hold values such 4
, 6.6
respectively (normally hold ajax return).
php code:
select avgreturns stocks avgreturns >= '$min_returns' , avgreturns <= '$max_returns'
in database, values 0.3 4.6, etc..
the problem getting decimals may not there. example, 1.3 valued 13, wouldn't included in example above. integers, 5, read , included above.
i new php , mysql together. there doing wrong in database, need set columns correct setting? know called in query returned string, there isn't way convert within query, there?
would avoid rounding values in database if @ possible.
single quotes denote string literals, you're forcing database compare values lexicographically. in order interpret them numerically, drop quotes:
select avgreturns stocks avgreturns >= $min_returns , avgreturns <= $max_returns
mandatory warning:
using string manipulation create query bad idea leaves vulnerable sql injection attacks. should use prepared statement instead.
Comments
Post a Comment