如何使用PHP中的dueDate变量计算罚款费用

时间:2019-04-11 17:05:15

标签: php

我试图计算某人在到期日之后提交一本书的罚款费用。它应该每天收取一定金额的费用,并在该人总共偿还了该金额后就停止收费。我想从数据库中的表中读取到期日期,并据此计算罚款费用。当我运行代码时,“应付金额”列会产生以下错误消息: “ 警告:strtotime()期望参数1为字符串,对象”和“ 致命错误:未被捕获的错误:调用C:\ xampp \ htdocs中未定义的FeesCalc()函数\ phplms \ librarian \ return_book.php:119堆栈跟踪:抛出#0 {main}

if(isset($_POST["submit"]))
    {
    $res = mysqli_query($link, "select * from issue_book where student_enrollment='$_POST[enr]' ");
    echo "<table class = 'table table-bordered'>";
    echo "<tr>";
    echo "<th>"; echo "student enrollement"; echo "</th>";
    echo "<th>"; echo "student name"; echo "</th>";
    echo "<th>"; echo "Amount Due"; echo "</th>";
    echo "</tr>";

    while($row = mysqli_fetch_array($res))
    {
    echo "<tr>";

    echo "<td>"; echo $row["student_enrollment"]; echo "</td>";
    echo "<td>"; echo $row["student_name"]; echo "</td>";
    echo "<td>"; ?><?php 
    $a = mysqli_query($link, "select due_date from issue_book where student_enrollment='$_POST[enr]' ");
    $due = date("Y/m/d",strtotime($a));
    $TodayDate = strtotime('today');

    $timeDiff = abs($TodayDate - strtotime($due));

    $numberDays = $timeDiff/86400;  // 86400 seconds in one day

    $numberDays = intval($numberDays);

    $noOfdaysToCheck ="6";

    $Fees ="0";

    if ($numberDays >= $noOfdaysToCheck){

     $Interval = $numberDays%$noOfdaysToCheck;

    for($i=1;$i<=$Interval;$i++){
     $late = "5";
    $Fees =  FeesCalc($Fees);

    }
    }

    $Fees = number_format($Fees, 2, '.', '');
    echo $Fees;

    function FeesCalc($Fees){
    $late = "5";
    return $TotalFees = $late+$Fees;

    }
    ?><?php  echo "</td>";

    echo "</tr>";

0 个答案:

没有答案