我有点坚持这个,它应该很简单,但我的大脑不能缠绕它(它是周五......哈哈)
我有一个温度计,代表最高1,000,000美元.它高375像素.
我正在运行数据库查询以从用户提交中获取金额(介于$ 1和$ 200之间).
在那个数学上,每像素的价格为2,666.66美元,将其向上移动1个像素---
retrieve_amount(); 是我的数据库功能,它可以获取所有金额 - 这很简单.
$fill_query = retrieve_amount();
$fill = 0;
$total = 0;
while($fill_query->is_valid() ) : $fill_query->amount();
$amount = get_valid_amount($input, 'amount');
$total = $total + $amount;
endwhile;
$finaltotal = $total; // THIS is the line that grabs the final total from above. Should work?
$fillheight = $SOMETHING +/-* $SOMETHING; // this is the line that i'm less sure of how to get my result
Run Code Online (Sandbox Code Playgroud)
可能我对数学不太满意,但我的问题是
$finaltotal = $total
Run Code Online (Sandbox Code Playgroud)
应该工作来接收从数据库查询中检索到的总金额,对吗?
更重要的是,我如何将其转换为我需要的像素?
$maxPixels = 375;
$maxAmount = 1000000;
$currentAmount = 1234567;
$currentPixels = round(($currentAmount / $maxAmount) * $maxPixels);
Run Code Online (Sandbox Code Playgroud)
它基本上就像计算百分比一样.除了,而不是100%,你的最大值现在是375像素.
| 归档时间: |
|
| 查看次数: |
112 次 |
| 最近记录: |