我有一张名为' treat_period'用于存储每只山羊接种疫苗的固定天数和用于存储购买山羊时的信息的order_details表。 现在,treat_period表具有以下列作为具有相应数据的列; id(1),productID(goat),treat1(90),treat2(180),treat3(270),treat4(360),annualtreat(365)。我想知道山羊是否分别停留了90天,180天。 这是我的代码,请帮忙。
<?php
$treat_query = mysql_query("select * from treat_period where productID='$product_id'") or die(mysql_error());
$treat_row = mysql_fetch_array($product_query);
$treatperiod1=$treat_row['treat1'];
$thisDate = date("Y-m-d");
$allDays = $treatperiod1;
$usedDays = round(abs(strtotime($thisDate)-strtotime($orderdate))/60/60/24);
$Daysremaining = $allDays-$usedDays;
if($Daysremaining==0)
{
echo "<a target = '_blank' href ='request_pay.php?order_id=$order_id&orderdate=$orderdate' class='btn btn-success'><i class='fa fa-pencil'></i>Vaccinate Gaoat</a>";
}
else
{
echo $Daysremaining.' Days Left for Vaccination';
}
?>
答案 0 :(得分:1)
$Daysremaining = ceil(abs(strtotime($thisDate) - strtotime($orderdate)) / 86400);
if($treatperiod1==$Daysremaining){
echo "<a target = '_blank' href ='request_pay.php?order_id=$order_id&orderdate=$orderdate' class='btn btn-success'><i class='fa fa-pencil'></i>Vaccinate Gaoat</a>";
}else {
echo $Daysremaining.' Days Left for Vaccination';
}
答案 1 :(得分:1)
我后来发现名为'treat_period'的表并没有替换<?php echo $treat_row['treat1']; ?>
之后存储的记录,但是如果来自order_details表的I <?php echo $product_row['name']; ?>
信息被取代,那么决定在order_details表中添加更多列(treat1,treat2等),使用相同的代码我现在可以获得预期的结果。请参阅此处的代码。
<?php
$treatperiod1=$product_row['treat1'];
$currentDate = date("Y-m-d");
$totalDays = $treatperiod1;
$usedDays = round(abs(strtotime($currentDate)-strtotime($orderdate))/60/60/24);
$remainingDays = $totalDays-$usedDays;
if($remainingDays==0)
{
echo "<a target = '_blank' href ='product_addon.php' class='btn btn-success'><i class='fa fa-pencil'></i>Vaccinate Gaoat</a>";
}
else
{
echo $remainingDays.' Days Left for Vaccination';
}
?>
感谢