Re: RES: [PHP] inexplicable behaviour SOLVED
2009/4/27 9el le...@phpxperts.net: Thanks for the clarification, Mike. In my ignorance, I was under the impression that the right side of the equation was only for the use of the left part. How stupid of me. So what I should have been doing was $Count1 = $Count + 1; right? $Count1 = $Count++; is not the same as $Count1 = $Count + 1; ?php $Count1 = 100; echo Start with $Count1, PHP_EOL; $Count1 = $Count1++; echo For \$Count1 = \$Count1++; the value in \$Count1 is $Count1, PHP_EOL; $Count1 = $Count1 + 1; echo For \$Count1 = \$Count1 + 1; the value in \$Count1 is $Count1, PHP_EOL; outputs ... Start with 100 For $Count1 = $Count1++; the value in $Count1 is 100 For $Count1 = $Count1 + 1; the value in $Count1 is 101 This shows that post-inc during an assignment does not affect the value assigned. Something that I thought would happen was if I ... ?php $Count1 = 100; echo $Count1 = $Count1++, PHP_EOL; echo $Count1, PHP_EOL; I thought I'd get ... 101 100 but I get 100 100 I thought the ++ would happen AFTER the assignment and the ++ to the value of the assignment. But this is not the case. $Count = $Count + 1; is exactly(?) same as $Count++; or ++$Count But not exactly same. PostFix notation adds the value after assigning. PreFix notation adds the value right away. But optimized programming argues about how machine is coded nowadays. Anyway, I don't need that statement anymore as I found the error of my ways and have corrected it. And behold, the light came forth and it worked. :-) Regards Lenin www.twitter.com/nine_L www.lenin9l.wordpress.com -- - Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731 Standing on the shoulders of some very clever giants! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: RES: [PHP] inexplicable behaviour SOLVED
Thats why I used a (?) after exactly. PJ didn't have a need for the value. ;)
RE: RES: [PHP] inexplicable behaviour SOLVED
On 27 April 2009 14:21, PJ advised: Ford, Mike wrote: On 26 April 2009 22:59, PJ advised: kranthi wrote: if $Count1 is never referenced after this, then certainly this assignment operation is redundent. but assignment is not the ONLY operation of this statement. if u hav not noticed a post increment operator has been used which will affect the value of $Count as well, and this operation is required for the script to work. the script should work even if u replace $Count1 = $Count++; with $Count++; Kranthi. Not quite, since that would change the $Count variable and that is used leater in the code. Um -- I must be missing something here, because those two statements have exactly the same effect on $Count, incrementing it by one (and you said the first statement fixed your problem, so logically the second one must too). In fact, because you've used a post-increment, the statement $Count1 = $Count++; ends up with $Count == $Count1+1, and $Count1 being the original value of $Count!! This whole scenario smacks to me of a classic off-by-one error -- either $Count actually *needs* to be one greater than the value you first thought of, or some other value you are comparing it to should be one smaller than it actually is. Cheers! Thanks for the clarification, Mike. In my ignorance, I was under the impression that the right side of the equation was only for the use of the left part. How stupid of me. So what I should have been doing was $Count1 = $Count + 1; right? No -- because, as you stated, $Count1 was not referred to anywhere else, so there was and would have been no usefulness in assigning any value to it. You could equally well have said $Count1 = 2.71828 + 3.14159 * $Count++; and got the same result -- because this still increments $Count by 1, and anything else the statement does is irrelevant if $Count1 is never referred to anywhere else!!! ;) ;) What you did worked because $Count++ *always* adds one to the value of $Count, no matter where it appears -- the crucial part of your original statement was the $Count++ bit, with the assignment to $Count1 being a massive red herring. For ultimate clarification, the following 4 statements all have identical effect: $Count = $Count + 1; $Count += 1; $Count++; ++$Count; and any one of them would have had the same effect on your result. This is why I say it was an off-by-one error -- your programming logic somehow *needed* $Count to be 1 greater than you thought it did, so the inadvertent incrementation of it was doing the trick for you. Hope this helps increase the illumination in your head a tiny bit more. Cheers! Mike -- Mike Ford, Electronic Information Developer, C507, Leeds Metropolitan University, Civic Quarter Campus, Woodhouse Lane, LEEDS, LS1 3HE, United Kingdom Email: m.f...@leedsmet.ac.uk Tel: +44 113 812 4730 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: RES: [PHP] inexplicable behaviour SOLVED
Ford, Mike wrote: On 27 April 2009 14:21, PJ advised: Ford, Mike wrote: On 26 April 2009 22:59, PJ advised: kranthi wrote: if $Count1 is never referenced after this, then certainly this assignment operation is redundent. but assignment is not the ONLY operation of this statement. if u hav not noticed a post increment operator has been used which will affect the value of $Count as well, and this operation is required for the script to work. the script should work even if u replace $Count1 = $Count++; with $Count++; Kranthi. Not quite, since that would change the $Count variable and that is used leater in the code. Um -- I must be missing something here, because those two statements have exactly the same effect on $Count, incrementing it by one (and you said the first statement fixed your problem, so logically the second one must too). In fact, because you've used a post-increment, the statement $Count1 = $Count++; ends up with $Count == $Count1+1, and $Count1 being the original value of $Count!! This whole scenario smacks to me of a classic off-by-one error -- either $Count actually *needs* to be one greater than the value you first thought of, or some other value you are comparing it to should be one smaller than it actually is. Cheers! Thanks for the clarification, Mike. In my ignorance, I was under the impression that the right side of the equation was only for the use of the left part. How stupid of me. So what I should have been doing was $Count1 = $Count + 1; right? No -- because, as you stated, $Count1 was not referred to anywhere else, so there was and would have been no usefulness in assigning any value to it. You could equally well have said $Count1 = 2.71828 + 3.14159 * $Count++; and got the same result -- because this still increments $Count by 1, and anything else the statement does is irrelevant if $Count1 is never referred to anywhere else!!! ;) ;) What you did worked because $Count++ *always* adds one to the value of $Count, no matter where it appears -- the crucial part of your original statement was the $Count++ bit, with the assignment to $Count1 being a massive red herring. For ultimate clarification, the following 4 statements all have identical effect: $Count = $Count + 1; $Count += 1; $Count++; ++$Count; and any one of them would have had the same effect on your result. This is why I say it was an off-by-one error -- your programming logic somehow *needed* $Count to be 1 greater than you thought it did, so the inadvertent incrementation of it was doing the trick for you. Hope this helps increase the illumination in your head a tiny bit more. Indeed, it does. Thanks. -- Hervé Kempf: Pour sauver la planète, sortez du capitalisme. - Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com/andypantry.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: RES: [PHP] inexplicable behaviour SOLVED
$Count = $Count + 1; is *exactly(?)* same as $Count++; Â or ++$Count But not exactly same. Â PostFix notation adds the value after assigning . PreFix notation adds the value right away. But optimized programming argues about how machine is coded nowadays. Thanks Mike for clarifying this much. Butt I already said those in brief I marked them in red now :) Lenin www.twitter.com/nine_L
Re: RES: [PHP] inexplicable behaviour SOLVED
Richard Quadling wrote: 2009/4/27 9el le...@phpxperts.net: Thanks for the clarification, Mike. In my ignorance, I was under the impression that the right side of the equation was only for the use of the left part. How stupid of me. So what I should have been doing was $Count1 = $Count + 1; right? $Count1 = $Count++; is not the same as $Count1 = $Count + 1; ?php $Count1 = 100; echo Start with $Count1, PHP_EOL; $Count1 = $Count1++; echo For \$Count1 = \$Count1++; the value in \$Count1 is $Count1, PHP_EOL; $Count1 = $Count1 + 1; echo For \$Count1 = \$Count1 + 1; the value in \$Count1 is $Count1, PHP_EOL; outputs ... Start with 100 For $Count1 = $Count1++; the value in $Count1 is 100 For $Count1 = $Count1 + 1; the value in $Count1 is 101 This shows that post-inc during an assignment does not affect the value assigned. Something that I thought would happen was if I ... ?php $Count1 = 100; echo $Count1 = $Count1++, PHP_EOL; echo $Count1, PHP_EOL; I thought I'd get ... 101 100 but I get 100 100 I thought the ++ would happen AFTER the assignment and the ++ to the value of the assignment. But this is not the case. $Count = $Count + 1; is exactly(?) same as $Count++; Â or ++$Count But not exactly same. Â PostFix notation adds the value after assigning. PreFix notation adds the value right away. But optimized programming argues about how machine is coded nowadays. Anyway, I don't need that statement anymore as I found the error of my ways and have corrected it. And behold, the light came forth and it worked. :-) Regards Lenin www.twitter.com/nine_L www.lenin9l.wordpress.com Thanks. That is really a nice eye-opener. Phil -- Hervé Kempf: Pour sauver la planète, sortez du capitalisme. - Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com/andypantry.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: RES: [PHP] inexplicable behaviour SOLVED
On 26 April 2009 22:59, PJ advised: kranthi wrote: if $Count1 is never referenced after this, then certainly this assignment operation is redundent. but assignment is not the ONLY operation of this statement. if u hav not noticed a post increment operator has been used which will affect the value of $Count as well, and this operation is required for the script to work. the script should work even if u replace $Count1 = $Count++; with $Count++; Kranthi. Not quite, since that would change the $Count variable and that is used leater in the code. Um -- I must be missing something here, because those two statements have exactly the same effect on $Count, incrementing it by one (and you said the first statement fixed your problem, so logically the second one must too). In fact, because you've used a post-increment, the statement $Count1 = $Count++; ends up with $Count == $Count1+1, and $Count1 being the original value of $Count!! This whole scenario smacks to me of a classic off-by-one error -- either $Count actually *needs* to be one greater than the value you first thought of, or some other value you are comparing it to should be one smaller than it actually is. Cheers! Mike -- Mike Ford, Electronic Information Developer, C507, Leeds Metropolitan University, Civic Quarter Campus, Woodhouse Lane, LEEDS, LS1 3HE, United Kingdom Email: m.f...@leedsmet.ac.uk Tel: +44 113 812 4730 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: RES: [PHP] inexplicable behaviour SOLVED
Ford, Mike wrote: On 26 April 2009 22:59, PJ advised: kranthi wrote: if $Count1 is never referenced after this, then certainly this assignment operation is redundent. but assignment is not the ONLY operation of this statement. if u hav not noticed a post increment operator has been used which will affect the value of $Count as well, and this operation is required for the script to work. the script should work even if u replace $Count1 = $Count++; with $Count++; Kranthi. Not quite, since that would change the $Count variable and that is used leater in the code. Um -- I must be missing something here, because those two statements have exactly the same effect on $Count, incrementing it by one (and you said the first statement fixed your problem, so logically the second one must too). In fact, because you've used a post-increment, the statement $Count1 = $Count++; ends up with $Count == $Count1+1, and $Count1 being the original value of $Count!! This whole scenario smacks to me of a classic off-by-one error -- either $Count actually *needs* to be one greater than the value you first thought of, or some other value you are comparing it to should be one smaller than it actually is. Cheers! Thanks for the clarification, Mike. In my ignorance, I was under the impression that the right side of the equation was only for the use of the left part. How stupid of me. So what I should have been doing was $Count1 = $Count + 1; right? Anyway, I don't need that statement anymore as I found the error of my ways and have corrected it. And behold, the light came forth and it worked. :-) Mike -- Mike Ford, Electronic Information Developer, C507, Leeds Metropolitan University, Civic Quarter Campus, Woodhouse Lane, LEEDS, LS1 3HE, United Kingdom Email: m.f...@leedsmet.ac.uk Tel: +44 113 812 4730 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm -- Hervé Kempf: Pour sauver la planète, sortez du capitalisme. - Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com/andypantry.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: RES: [PHP] inexplicable behaviour SOLVED
Thanks for the clarification, Mike. In my ignorance, I was under the impression that the right side of the equation was only for the use of the left part. How stupid of me. So what I should have been doing was $Count1 = $Count + 1; right? $Count = $Count + 1; is exactly(?) same as $Count++; or ++$Count But not exactly same. PostFix notation adds the value after assigning. PreFix notation adds the value right away. But optimized programming argues about how machine is coded nowadays. Anyway, I don't need that statement anymore as I found the error of my ways and have corrected it. And behold, the light came forth and it worked. :-) Regards Lenin www.twitter.com/nine_L www.lenin9l.wordpress.com
Re: RES: [PHP] inexplicable behaviour SOLVED
kranthi wrote: if $Count1 is never referenced after this, then certainly this assignment operation is redundent. but assignment is not the ONLY operation of this statement. if u hav not noticed a post increment operator has been used which will affect the value of $Count as well, and this operation is required for the script to work. the script should work even if u replace $Count1 = $Count++; with $Count++; Kranthi. Not quite, since that would change the $Count variable and that is used leater in the code. But the problem seems to be solved as the paging needed the $Count1 wich was not being supplied because I was debugging the code without enough entries in the database. Once I had a larger base of info I was able to see what the problem was. The code needed to determine how many instances there are in the db of the search criteria and it was not getting that; it was only getting the LIMIT of the query. So I added a few lines to determine the total for $Count1 and it all works fine now. :-) or until I find another glitch. ;-) Thanks for the suggestion. -- unheralded genius: A clean desk is the sign of a dull mind. - Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com/andypantry.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php