How to subtract a value in php mysql? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
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 Réponse
+ 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