あなたは価値のオフ割合を取りたい場合は、あなたが目を呼び出すことができコーディングあなたのPDOおよびSQLで
// this function returns amount after discount
function calcDiscount($percentage, $pay){
return $pay - (($percentage/100) * $pay);
}
// call the function
$pay = 1500;
$discount = 20;
$pay2 = calcDiscount($discount, $pay);
ので、この機能を使用することができます電子機能:MySQLの文の場合
//this code works for this $id. For multiple id's you will need a loop
$id = 1;
$discount = 20;
$conn = pdo_connect();
$sql = 'SELECT Pay1
FROM Your_Table
WHERE ID = :ID';
$statement = $conn->prepare($sql);
$statement->bindValue(":ID", $id, PDO::PARAM_STR);
$statement->execute();
// 1. get the pay1 from the row
$result = $statement->fetchAll(PDO::FETCH_ASSOC);
// store the value in a variable
$pay = $result[0]['Pay1'];
// 2. calculate the discount for Pay1
$pay2 = calcDiscount($discount, $pay);
// 3. update the column for pay2
$sql = 'UPDATE Your_Table
SET Pay2 = :pay2
WHERE ID = :ID';
$statement = $conn->prepare($sql);
$statement->bindValue(":pay2", $pay2, PDO::PARAM_INT);
$statement->bindValue(":ID", $id, PDO::PARAM_STR);
$statement->execute();
$conn = null;
、あなたが実際に
だからあなたはこの式を試してみました列の値を変更するには、テーブルとUPDATEから賃金をつかむためにSELECTを使用したいですか?期待どおりに動作しないのですか? – WillardSolutions
これは20%割引を提供する方法です。あなたはそれを試しましたか? – sheplu
私は数式を試していません。私はどのように選択または挿入を使用する必要があり、どのように開始するのか分からない。私は良い例を見つけようとしています。 – TD00