我有一張圖表,基於幾個值自動填充。這些值是目標(總計)當前(現在的位置)和圖形的總高度。我試圖將目標和目前的數據庫格式轉化爲金錢,並且應該將圖表填充到需要的位置。PHP MySQL從表格中讀取以用於圖表
我讓它使用了一個URL,它是?current=584559096&goal=1000000000
,我只用$ _GET。爲了更容易維護周圍的人,我想從一個可以更新的帖子中提取數據庫。
我到目前爲止的代碼是:
<? php function formatMoney($number, $fractional=false) {
if ($fractional) {
$number = sprintf('%.0f', $number);
}
while (true) {
$replaced = preg_replace('/(-?\d+)(\d\d\d)/', '$1,$2', $number);
if ($replaced != $number) {
$number = $replaced;
} else {
break;
}
}
return $number;
}
$goal = $row['goal'];
$current = $row['current'];
$percent = round($current/$goal * 100);
$totalheight = 216;
$ourheight = $totalheight * $percent/100;
$halfofarrowheight = 12;
$arrowheight = $totalheight-$ourheight-$halfofarrowheight;
if($arrowheight < 0)
$arrowheight = 0;
mysql_close($con);
?>
這裏是我的查詢
mysql_select_db("databasename", $con);
$result = mysql_query("select * from `dbname`.`tablename");
這是我的錯誤警告:被零除在E:\的Inetpub \ wwwroot的\ test.website .NET \網絡\包括\ globalfoot.php在線路36上36
行是$percent = round($current/$goal * 100);
所以,我一直在玩弄這個東西4天,現在試圖從目標列和當前列中將數字格式化爲金錢並填入圖表。對於測試的緣故可以說,我們的目標是萬億,電流爲5000000000.
凡'$ row'越來越設定?你可以顯示該代碼嗎? –