How to subtract a value in php mysql? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to subtract a value in php mysql?

$value1 = "SELECT value FROM price WHERE id = '1' "; //example the value is 200 $value2 = 100; $subtract = $value1 - $value2; But the result is: -99 How?

12th Jan 2020, 5:16 PM
Rizqi Syaiful Rijal
Rizqi Syaiful Rijal - avatar
1 Answer
+ 1
The <$value1> variable is a SQL query string, not the query result. You need to execute the SQL query string and obtain the result to achieve your actual intention. * Please confirm this by adding `echo $value1;` before declaration of <$value2> variable. It is not a good idea to do an operation involving two different types, it will most likely give weird result.
13th Jan 2020, 8:52 AM
Ipang