variables - How to subtract db values using php -


how subtract values database using php? see plenty of examples using static variables such

<?php $first_number = 10; $second_number = 2; $third_number = 3; $sum_total = $third_number + $second_number * $first_number; print ($sum_total); ?> 

however i'm looking subtract 1 database value another, multiply value db value. give more detail, have inventory database i'm echoing values table, i'm attempting subtract total quantity of item minimum quantity, see how many need ordered, multiply number of parts need order cost of part. i've dug around , found few possible methods such as

$query = "select `db`,           (`minimumquantity` - `totalquantity`) `quantitytoorder`         `db`          id ='".$id."';" 

and

<?php $minimumquantity = $_get['minimumquantity']; $totalquantity = $_get['totalquantity'];  $quantitytoorder = $minimumquantity - $totalquantity; print ($quantitytoorder); ?> 

please before laugh, i'm beginner, can point me in right direction, or provide me proper examples? real resource net , examples find high-level.

field             type        null     key   default     id                int(3)      no       pri   null     auto_increment  partnumber        varchar(20) no             null   description       varchar(20) no             null   tonerprice        int(20)     no             null   totalquantity     int(20)     no             null   minimumquantity   int(20)     no             null   quantitytoorder   int(20)     no             null   replencost        int(20)     no             null   

so assuming know how work sql in php, it's simple this:

// stop using mysql, use mysqli or pdo, demonstration purposes $results = mysql_query('select foo, bar, baz table');  while ($row = mysql_fetch_assoc($results)) {     echo $row['foo'] - $row['bar'] * $row['baz']; } 

assuming columns numeric, that's need subtract , multiply values database in php.


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -