1

I want to print information with the help of second while loop, but it is running only once.

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'];
        }
}
6
  • you have not closed first while loop } is missing OR its just TYPO. Commented Feb 22, 2013 at 7:42
  • I see no printing statements in your second loop. Commented Feb 22, 2013 at 7:42
  • what o/p you are getting now? Also what is you expected o/p? Commented Feb 22, 2013 at 7:42
  • @Manu Srivastava may be your 2nd sql query is returning only one row. Commented Feb 22, 2013 at 7:44
  • Where is the declaration of $currentDate? Commented Feb 22, 2013 at 7:45

2 Answers 2

1

Judging by your code, there are too many unknowns to figure out the issue.

But I wrote some comments in the code to point out potential problems / debugging suggestions:

// 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'];
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0

$nextDate is always greater than $currentDate because you are adding 6 days

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

2 Comments

Not sure that's true. is $weekDate the same as $currentDate?
Not necessarily, we don't know the value of $weekDate. If would seem to me that the first while would either run once, or an infinite loop, since $weekDate isn't changed :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.