-1
我想從數據庫中獲取的數字運行總和。但是,我似乎無法得到它的工作。從數據庫計算不正確的PHP計算。
有沒有人有任何想法,爲什麼我一直得到0而不是百分比?如果是的話,你可以指導我朝着正確的方向前進。
PHP:
//SQL Original Goal
$goal = "SELECT * FROM login WHERE username = '$login'";
$goalquery = mysql_query($goal);
$goalarray = mysql_fetch_array($goalquery);
$endgoal = $goalarray['goal'];
//Latest Weight
$latestweightarray = mysql_fetch_array($latestweightq);
$currentweight = $latestweightarray['weight'];
//First Weight Recorded
$firstweightarray = mysql_fetch_array($firstweightq);
$firstweight = $firstweightarray['weight'];
$percent = "100";
$progress = (($firstweight - $currentweight)/($firstweight - $endgoal)) * $percent;
打印結果:
<?php
echo $progress
?>
這只是給:0
這是在哪裏分配的? '$ latestweightq'和'$ firstweightq' –
構成$ progress公式的值是什麼?如果三個部分中的任何一個都爲0,則答案將爲0. - 如果$ firstweight == $ currentweight或$ firstweight == $ endgoal? – ggdx
'error_reporting(E_ALL); ini_set('display_errors','1');' – AbraCadaver