0

我想在第二个 while 循环的帮助下打印信息,但它只运行一次。

while($nextDate<$currentDate)
{
        $nextDate=date('Y-m-d',strtotime('+ 6 days',strtotime($weekDate))); 

        $qM="select count(*) as count ,Deposit.DepositNo, Deposit.DepositDate,
                     sum(DepositItem.Amount) as Amount,DAmount
                     from DepositItem
                     inner join Deposit on Deposit.DepositNo=DepositItem.DepositNo
                     where Deposit.DepositDate>='".$weekDate."' and Deposit.DepositDate<='".$nextDate."' group by Deposit.DepositNo 
                     order by Deposit.DepositNo desc";

        $connM=new dbconfig();
        $connM->connectdb();
        $connM->execute($qM);
        $amt=0;
        $damt=0;
        while($rowsM =$connM->fetch_row()) 
        {
            $amt=$amt+$rowsM['Amount'];
            $damt=$damt+$rowsM['DAmount'];
        }
}
4

2 回答 2

0

$nextDate 总是大于 $currentDate 因为您要添加 6 天

$nextDate=date('Y-m-d',strtotime('+ 6 days',strtotime($weekDate))); 
于 2013-02-22T07:42:54.037 回答
0

从您的代码来看,有太多未知数无法解决问题。

但是我在代码中写了一些注释来指出潜在的问题/调试建议:

// what are the (expected) values of $nextDate and $currentDate ?
while ($nextDate < $currentDate) {
    $nextDate = date('Y-m-d', strtotime('+ 6 days', strtotime($weekDate)));
    // this makes the big loop either run once (if $weekDate is within the 6 days interval)
    // or an infinite loop if it isn't

    $qM =   "select count(*) as count ,Deposit.DepositNo, Deposit.DepositDate,
             sum(DepositItem.Amount) as Amount,DAmount
             from DepositItem
             inner join Deposit on Deposit.DepositNo=DepositItem.DepositNo
             where Deposit.DepositDate>='" . $weekDate . "' and Deposit.DepositDate<='" . $nextDate . "' group by Deposit.DepositNo 
             order by Deposit.DepositNo desc";
    // do an echo $qM and copy it in Phpmyadmin, see if it returns expected results

    $connM = new dbconfig(); // not quite good to have these inside a loop
    $connM->connectdb(); // you should put these 2 lines outside
    $connM->execute($qM);
    $amt = 0;
    $damt = 0;
    while ($rowsM = $connM->fetch_row()) { // do a var_dump($rowsM) inside the loop
        $amt = $amt + $rowsM['Amount'];
        $damt = $damt + $rowsM['DAmount'];
    }
}
于 2013-02-22T08:02:52.480 回答