我有一个药物表格,用户输入他们的药物名称,他们从药房收集的数量(例如,24片),每个剂量必须服用的量和每个剂量之间的时间间隔。我需要在服用每种剂量后扣除总量(例如)。我把一些代码作为一个开始,但我不确定如何在“经过一段时间后”说明:
//Deduct Medication Amount After Time
//Define Variables
$TimeHour = 3600;
$TimeDay = 86400;
$TimeWeek = 604800;
if ($MedEntriesTimeScale == "Hours")
{
$SecondsAmt = $MedEntriesTimeNumber * $TimeHour;
//When $SecondsAmt has elapsed
$AmountLeft = $MedEntriesPharmacyAmt - $MedEntriesAmountPerDosage;
}
if ($MedEntriesTimeScale == "Days")
{
$SecondsAmt = $MedEntriesTimeNumber * $TimeDay;
//When $SecondsAmt has elapsed
$AmountLeft = $MedEntriesPharmacyAmt - $MedEntriesAmountPerDosage;
}
if ($MedEntriesTimeScale == "Weeks")
{
$SecondsAmt = $MedEntriesTimeNumber * $TimeWeek;
//When $SecondsAmt has elapsed
$AmountLeft = $MedEntriesPharmacyAmt - $MedEntriesAmountPerDosage;
}
根据我的数据库;
$MedEntriesTimeScale
- 可以是小时,天或周。
$MedEntriesTimeNumber
- 小时数,天数或周数。
$MedEntriesPharmacyAmt
- 最初从药房收取的总金额(例如24片)
$MedEntriesAmountPerDosage
- 每个剂量(例如2片)用户应服用的量
答案 0 :(得分:2)
假设您有用于计算经过时间的原始接送日期,这里有一个例子(注意:这可能写得更简单但我不知道你的目标是什么所以我只是离开它就像你现在写的那样):
<?php
//Deduct Medication Amount After Time
//Define Variables
$TimeHour = 3600;
$TimeDay = 86400;
$TimeWeek = 604800;
// Example date
$date_picked_up = 'Feb 1, 2014 10:00am';
// Date converted into time
$time_picked_up = strtotime($date_picked_up);
// Time difference between now and time picked up
$elapsed = time() - $time_picked_up;
if ($MedEntriesTimeScale == "Hours")
{
$SecondsAmt = $MedEntriesTimeNumber * $TimeHour;
//When $SecondsAmt has elapsed
if ($elapsed >= $SecondsAmt) {
$AmountLeft = $MedEntriesPharmacyAmt - $MedEntriesAmountPerDosage;
}
}
if ($MedEntriesTimeScale == "Days")
{
$SecondsAmt = $MedEntriesTimeNumber * $TimeDay;
//When $SecondsAmt has elapsed
if ($elapsed >= $SecondsAmt) {
$AmountLeft = $MedEntriesPharmacyAmt - $MedEntriesAmountPerDosage;
}
}
if ($MedEntriesTimeScale == "Weeks")
{
$SecondsAmt = $MedEntriesTimeNumber * $TimeWeek;
//When $SecondsAmt has elapsed
if ($elapsed >= $SecondsAmt) {
$AmountLeft = $MedEntriesPharmacyAmt - $MedEntriesAmountPerDosage;
}
}