keenej Posted September 5, 2008 Share Posted September 5, 2008 IM not sure what IM doing wrong here, but the code within the if statement never executes. The Dates Change I used the echo statment to see the dates and tmpDATE1 always = tmpDATE2. Please take a look at the code and point me in the right direction. Thanks while (!$rs->EOF) { $tmpDATE1=$rs->Fields('CountedDate'); echo $tmpDATE1; echo $tmpDATE2; if($tmpDATE1<>$tmpDATE2){ echo "DATE CHANGED"; $tmpDATE2=$tmpDATE1; $tmpACOUNT=0; $tmpBCOUNT=0; $tmpCCOUNT=0; } if($rs->Fields('ABC')=="A"){ $tmpACOUNT++; } if($rs->Fields('ABC')=="B"){ $tmpBCOUNT++; } if($rs->Fields('ABC')=="C"){ $tmpCCOUNT++; } $tmpX = $tmpX + 1; echo "<tr>"; echo "<td align='Left'>$tmpX</td>"; echo "<td align='Left'>$tmpDATE2</td>"; echo "<td align='Left'>$tmpPART</td>"; echo "<td align='Left'>$tmpACOUNT</td>"; echo "<td align='Left'>$tmpBCOUNT</td>"; echo "<td align='Left'>$tmpCCOUNT</td>"; echo "</tr>"; $rs->MoveNext(); } Quote Link to comment https://forums.phpfreaks.com/topic/122891-solved-unknown-issue-php-sql/ Share on other sites More sharing options...
Mchl Posted September 5, 2008 Share Posted September 5, 2008 Which if statment gives you a problem? Quote Link to comment https://forums.phpfreaks.com/topic/122891-solved-unknown-issue-php-sql/#findComment-634698 Share on other sites More sharing options...
keenej Posted September 5, 2008 Author Share Posted September 5, 2008 $tmpDATE1=$rs->Fields('CountedDate'); echo $tmpDATE1; echo $tmpDATE2; if($tmpDATE1<>$tmpDATE2){ echo "DATE CHANGED"; $tmpDATE2=$tmpDATE1; $tmpACOUNT=0; $tmpBCOUNT=0; $tmpCCOUNT=0; } Quote Link to comment https://forums.phpfreaks.com/topic/122891-solved-unknown-issue-php-sql/#findComment-634700 Share on other sites More sharing options...
Mchl Posted September 5, 2008 Share Posted September 5, 2008 But you say that $tmpDATE1 is always equal to $tmpDATE2 ??? Quote Link to comment https://forums.phpfreaks.com/topic/122891-solved-unknown-issue-php-sql/#findComment-634704 Share on other sites More sharing options...
keenej Posted September 5, 2008 Author Share Posted September 5, 2008 Result should be like below. Except where 13 is printed a second time should be a 0 and where the 1 is on the second 13 should be there, but the next value should be 0. Only 1 of the 3 numbers in each row should have a value and increment to the next time that column has a certain value. A B or C Hope this helps a little more. 9/2/20089/2/2008 1 9/2/2008 1 0 0 9/2/20089/2/2008 2 9/2/2008 2 0 0 9/2/20089/2/2008 3 9/2/2008 3 0 0 9/2/20089/2/2008 4 9/2/2008 4 0 0 9/2/20089/2/2008 5 9/2/2008 5 0 0 9/2/20089/2/2008 6 9/2/2008 6 0 0 9/2/20089/2/2008 7 9/2/2008 7 0 0 9/2/20089/2/2008 8 9/2/2008 8 0 0 9/2/20089/2/2008 9 9/2/2008 9 0 0 9/2/20089/2/2008 10 9/2/2008 10 0 0 9/2/20089/2/2008 11 9/2/2008 11 0 0 9/2/20089/2/2008 12 9/2/2008 12 0 0 9/2/20089/2/2008 13 9/2/2008 13 0 0 9/2/20089/2/2008 14 9/2/2008 13 0 1 9/3/20089/3/2008 15 9/3/2008 14 0 1 Quote Link to comment https://forums.phpfreaks.com/topic/122891-solved-unknown-issue-php-sql/#findComment-634708 Share on other sites More sharing options...
keenej Posted September 5, 2008 Author Share Posted September 5, 2008 Yes. Its completely weird. $tmpDATE2 is changing without entering the if statement Quote Link to comment https://forums.phpfreaks.com/topic/122891-solved-unknown-issue-php-sql/#findComment-634710 Share on other sites More sharing options...
keenej Posted September 5, 2008 Author Share Posted September 5, 2008 I think the if statement syntax is correct, but I don't know how the $tmpDATE2 value is being set without entering the if Statement Quote Link to comment https://forums.phpfreaks.com/topic/122891-solved-unknown-issue-php-sql/#findComment-634711 Share on other sites More sharing options...
keenej Posted September 5, 2008 Author Share Posted September 5, 2008 here is the complete block of code. $tmpX = 0; $rs = $conn->Execute("SELECT * FROM [ABC Parts Counted By Reason] WHERE ABC_LogCounted.ABCREASON<>21 AND CountedDate Between #$BD# AND #$ED# ORDER BY CountedDate ASC"); while (!$rs->EOF) { $tmpDATE1=$rs->Fields('CountedDate'); echo $tmpDATE1; echo $tmpDATE2; if($tmpDATE1<>$tmpDATE2){ echo "DATE CHANGED"; $tmpDATE2=$tmpDATE1; $tmpACOUNT=0; $tmpBCOUNT=0; $tmpCCOUNT=0; } if($rs->Fields('ABC')=="A"){ $tmpACOUNT++; } if($rs->Fields('ABC')=="B"){ $tmpBCOUNT++; } if($rs->Fields('ABC')=="C"){ $tmpCCOUNT++; } $tmpX = $tmpX + 1; echo "<tr>"; echo "<td align='Left'>$tmpX</td>"; echo "<td align='Left'>$tmpDATE2</td>"; echo "<td align='Left'>$tmpPART</td>"; echo "<td align='Left'>$tmpACOUNT</td>"; echo "<td align='Left'>$tmpBCOUNT</td>"; echo "<td align='Left'>$tmpCCOUNT</td>"; echo "<td align='Left'>$tmpDATE</td>"; echo "<td align='Left'>$tmpDATE</td>"; echo "<td align='Left'>$tmpDATE</td>"; echo "<td align='Left'>$tmpDATE</td>"; echo "<td align='Left'>$tmpDATE</td>"; echo "<td align='Left'>$tmpDATE</td>"; echo "<td align='Left'>$tmpDATE</td>"; echo "</tr>"; $rs->MoveNext(); } Quote Link to comment https://forums.phpfreaks.com/topic/122891-solved-unknown-issue-php-sql/#findComment-634712 Share on other sites More sharing options...
Mchl Posted September 5, 2008 Share Posted September 5, 2008 It is strange. So "DATE CHANGED" is never echoed, and counters are not zeroed... Quote Link to comment https://forums.phpfreaks.com/topic/122891-solved-unknown-issue-php-sql/#findComment-634718 Share on other sites More sharing options...
keenej Posted September 5, 2008 Author Share Posted September 5, 2008 Its strange. IM new to php, but I put similar code in VB it works flawless. Do you see anything wrong with the code? Quote Link to comment https://forums.phpfreaks.com/topic/122891-solved-unknown-issue-php-sql/#findComment-634720 Share on other sites More sharing options...
Mchl Posted September 5, 2008 Share Posted September 5, 2008 I've even put it in php tags to get it coloured. Can't see anything wrong. $tmpX = 0; $rs = $conn->Execute("SELECT * FROM [ABC Parts Counted By Reason] WHERE ABC_LogCounted.ABCREASON<>21 AND CountedDate Between #$BD# AND #$ED# ORDER BY CountedDate ASC"); while (!$rs->EOF) { $tmpDATE1=$rs->Fields('CountedDate'); echo $tmpDATE1; echo $tmpDATE2; if($tmpDATE1<>$tmpDATE2){ echo "DATE CHANGED"; $tmpDATE2=$tmpDATE1; $tmpACOUNT=0; $tmpBCOUNT=0; $tmpCCOUNT=0; } if($rs->Fields('ABC')=="A"){ $tmpACOUNT++; } if($rs->Fields('ABC')=="B"){ $tmpBCOUNT++; } if($rs->Fields('ABC')=="C"){ $tmpCCOUNT++; } $tmpX = $tmpX + 1; echo "<tr>"; echo "<td align='Left'>$tmpX</td>"; echo "<td align='Left'>$tmpDATE2</td>"; echo "<td align='Left'>$tmpPART</td>"; echo "<td align='Left'>$tmpACOUNT</td>"; echo "<td align='Left'>$tmpBCOUNT</td>"; echo "<td align='Left'>$tmpCCOUNT</td>"; echo "<td align='Left'>$tmpDATE</td>"; echo "<td align='Left'>$tmpDATE</td>"; echo "<td align='Left'>$tmpDATE</td>"; echo "<td align='Left'>$tmpDATE</td>"; echo "<td align='Left'>$tmpDATE</td>"; echo "<td align='Left'>$tmpDATE</td>"; echo "<td align='Left'>$tmpDATE</td>"; echo "</tr>"; $rs->MoveNext(); } [edit] It echoes "DATE CHANGED" on my server (I had to get rid of all database stuff obviously) Quote Link to comment https://forums.phpfreaks.com/topic/122891-solved-unknown-issue-php-sql/#findComment-634721 Share on other sites More sharing options...
keenej Posted September 5, 2008 Author Share Posted September 5, 2008 I'll keep messing with it. And post the cure If I can figure it out. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/122891-solved-unknown-issue-php-sql/#findComment-634726 Share on other sites More sharing options...
Mchl Posted September 5, 2008 Share Posted September 5, 2008 One more thing that came to my mind: perhaps you have a reference for $tmpDATE1 and $tmpDATE2 set up somewhere? References in PHP manual Quote Link to comment https://forums.phpfreaks.com/topic/122891-solved-unknown-issue-php-sql/#findComment-634728 Share on other sites More sharing options...
keenej Posted September 5, 2008 Author Share Posted September 5, 2008 IM not sure how to mark this as resolved, but thanks MCHL. I looked into referencing and that is what was happening. This is the fix if($tmpDATE!=$preDATE){ $preDATE=$tmpDATE; $tmpDATE=$rs->Fields('countedDATE'); $tmpACOUNT=0; $tmpBCOUNT=0; $tmpCCOUNT=0; } Had to create a fake date before the query runs forcing the if statement to be true. You have to set the referenced variables in the above order or else they will always return the same value. Set First Variable Set Second Variable = to First Variable Change 1st Variable. That was confusing. Thanks Again Quote Link to comment https://forums.phpfreaks.com/topic/122891-solved-unknown-issue-php-sql/#findComment-634802 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.