I need to do a mysql query but Im not sure how to go about it.
I want to select rows that are greater than the php value of $x, by adding 2 of the table fields together (after dividing them).
The pseudo code:
SELECT * FROM table WHERE (field_a/50 + field_b/20) > $x
The $x is a php value, its just the sum i need.
Anyone have tips?
It’s pretty much the pseudo-code you wrote:
Using parameters is more elegant, but you got the idea. This way you can mess the SQL query if
$xis empty or have any not expected value. I handled this issue escaping the value usingmysql_real_escape_stringbefore using it in the query.EDIT
The same example using MySQLi: