0

2 番目の while ループを使用して情報を出力したいのですが、実行は 1 回だけです。

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

コードから判断すると、不明な点が多すぎて問題を把握できません。

しかし、潜在的な問題/デバッグの提案を指摘するために、コードにいくつかのコメントを書きました:

// 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 に答える
0

6 日を追加しているため、$nextDate は常に $currentDate より大きくなります

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