RE: [PHP] Simple: Whats wrong with this?
On 17 March 2004 17:09, Chris W. Parker wrote: $var++ is a post incrementer meaning the value is updated at the next command*. * i'm not exactly sure how the compiler determines when to post increment, but i think i'm correct. Not quite -- the increment is performed immediately after the access -- in fact, as part of the same operation. So: $x = 3; $y = ($x++ * 2) + $x; is likely to give you $y==10, not 9. (I say is likely to, because you don't have any absolute cast-iron guarantees that a compiler won't, if it thinks it has good reason, commute the above to $x + ($x++ * 2), which would give you $y==9! In general, it's best to regard the value of a pre- or post-incremented variable as uncertain in the rest of the expression containing it.) Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Simple: Whats wrong with this?
Ford, Mike LSS on Thursday, March 18, 2004 5:02 AM said: Not quite -- the increment is performed immediately after the access -- in fact, as part of the same operation. So: $x = 3; $y = ($x++ * 2) + $x; is likely to give you $y==10, not 9. i see. good example. chris. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Simple: Whats wrong with this?
No. $correct++; Is all you need for the second condition, it automatically sets itself back. On Wed, 2004-03-17 at 11:52, Shane McBride wrote: I have a form variable I want to increment by a value of 1 each time the page loads. Here's what I have so far: if(!isset($correct)) { $correct = 0; } else { $correct = $correct++; } Seems like it should work? Thanks! Shane -- Adam Voigt [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Simple: Whats wrong with this?
No. $correct++; Is all you need for the second condition, it automatically sets itself back. Does this always work? In my timesheet app, I have to do $counter = $counter + 1, because for some reason the $counter++; doesn't work. It just doesn't work, no incrementation of the variable. Is there something in php.ini that can prohibit this from working? Thanks, Jake -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Simple: Whats wrong with this?
It doesn't seem to work either way for me. Shane -Original Message- From: Jake McHenry [mailto:[EMAIL PROTECTED] Sent: Wednesday, March 17, 2004 12:01 PM To: [EMAIL PROTECTED] Subject: Re: [PHP] Simple: Whats wrong with this? No. $correct++; Is all you need for the second condition, it automatically sets itself back. Does this always work? In my timesheet app, I have to do $counter = $counter + 1, because for some reason the $counter++; doesn't work. It just doesn't work, no incrementation of the variable. Is there something in php.ini that can prohibit this from working? Thanks, Jake -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Simple: Whats wrong with this?
Not that I'm aware of. In every incantation I've ever seen of the incrementing, $correct++; Is always, 100% equal to: $correct = ($correct + 1); But, maybe you ran into a case where it's not, you never know. On Wed, 2004-03-17 at 12:00, Jake McHenry wrote: No. $correct++; Is all you need for the second condition, it automatically sets itself back. Does this always work? In my timesheet app, I have to do $counter = $counter + 1, because for some reason the $counter++; doesn't work. It just doesn't work, no incrementation of the variable. Is there something in php.ini that can prohibit this from working? Thanks, Jake -- Adam Voigt [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Simple: Whats wrong with this?
This drove me nuts for a while and instead of doing $variable++ I started using ++$variable and never had the problem again. --Sam Jake McHenry wrote: No. $correct++; Is all you need for the second condition, it automatically sets itself back. Does this always work? In my timesheet app, I have to do $counter = $counter + 1, because for some reason the $counter++; doesn't work. It just + doesn't work, no incrementation of the variable. Is there something in php.ini that can prohibit this from working? Thanks, Jake -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Simple: Whats wrong with this?
Well I accidentally deleted your original email, but I didn't see where you were getting the counter variable from. Where is the variable being stored? You do know that setting $counter++ for one visitor, doesn't translate the value of $counter to another, right? On Wed, 2004-03-17 at 12:05, Shane McBride wrote: It doesn't seem to work either way for me. Shane -Original Message- From: Jake McHenry [mailto:[EMAIL PROTECTED] Sent: Wednesday, March 17, 2004 12:01 PM To: [EMAIL PROTECTED] Subject: Re: [PHP] Simple: Whats wrong with this? No. $correct++; Is all you need for the second condition, it automatically sets itself back. Does this always work? In my timesheet app, I have to do $counter = $counter + 1, because for some reason the $counter++; doesn't work. It just doesn't work, no incrementation of the variable. Is there something in php.ini that can prohibit this from working? Thanks, Jake -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Adam Voigt [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Simple: Whats wrong with this?
Maybe you guys should take a read about pre- and post-increment :-) Sam Masiello wrote: This drove me nuts for a while and instead of doing $variable++ I started using ++$variable and never had the problem again. --Sam Jake McHenry wrote: No. $correct++; Is all you need for the second condition, it automatically sets itself back. Does this always work? In my timesheet app, I have to do $counter = $counter + 1, because for some reason the $counter++; doesn't work. It just + doesn't work, no incrementation of the variable. Is there something in php.ini that can prohibit this from working? Thanks, Jake -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Simple: Whats wrong with this?
Jake McHenry mailto:[EMAIL PROTECTED] on Wednesday, March 17, 2004 9:01 AM said: Does this always work? In my timesheet app, I have to do $counter = $counter + 1, because for some reason the $counter++; doesn't work. It just doesn't work, no incrementation of the variable. Is there something in php.ini that can prohibit this from working? $var++ is a post incrementer meaning the value is updated at the next command*. ++$var is a pre increment meaning the value is updated immediately. is it possible you are expecting the results of ++$var? try this and see what happens: ?php $var = 2; echo $var++ . br; echo ++$var . br; ? also, i don't know of anything in the php.ini that would turn this short hand off. seems unlikely that there is. chris. * i'm not exactly sure how the compiler determines when to post increment, but i think i'm correct. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Simple: Whats wrong with this?
I am just trying to get the variable to increment, than I will be working on a session. It's basically being used to keep track of correct/incorrect answers for an online quiz. Here's what I am trying: if(!isset($correct)) { $correct = 0; } else { $correct++ } Shane -Original Message- From: Adam Voigt [mailto:[EMAIL PROTECTED] Sent: Wednesday, March 17, 2004 12:06 PM To: Shane McBride Cc: PHP Subject: RE: [PHP] Simple: Whats wrong with this? Well I accidentally deleted your original email, but I didn't see where you were getting the counter variable from. Where is the variable being stored? You do know that setting $counter++ for one visitor, doesn't translate the value of $counter to another, right? On Wed, 2004-03-17 at 12:05, Shane McBride wrote: It doesn't seem to work either way for me. Shane -Original Message- From: Jake McHenry [mailto:[EMAIL PROTECTED] Sent: Wednesday, March 17, 2004 12:01 PM To: [EMAIL PROTECTED] Subject: Re: [PHP] Simple: Whats wrong with this? No. $correct++; Is all you need for the second condition, it automatically sets itself back. Does this always work? In my timesheet app, I have to do $counter = $counter + 1, because for some reason the $counter++; doesn't work. It just doesn't work, no incrementation of the variable. Is there something in php.ini that can prohibit this from working? Thanks, Jake -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Adam Voigt [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Simple: Whats wrong with this?
Shane McBride mailto:[EMAIL PROTECTED] on Wednesday, March 17, 2004 9:16 AM said: I am just trying to get the variable to increment, than I will be working on a session. It's basically being used to keep track of correct/incorrect answers for an online quiz. and so now that you've corrected your code what are the results you are getting? are they not what you expect/want? chris. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Simple: Whats wrong with this?
No, the value still is not incrementing. -Original Message- From: Chris W. Parker [mailto:[EMAIL PROTECTED] Sent: Wednesday, March 17, 2004 12:25 PM To: Shane McBride; PHP; [EMAIL PROTECTED] Subject: RE: [PHP] Simple: Whats wrong with this? Shane McBride mailto:[EMAIL PROTECTED] on Wednesday, March 17, 2004 9:16 AM said: I am just trying to get the variable to increment, than I will be working on a session. It's basically being used to keep track of correct/incorrect answers for an online quiz. and so now that you've corrected your code what are the results you are getting? are they not what you expect/want? chris. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Simple: Whats wrong with this?
Shane McBride mailto:[EMAIL PROTECTED] on Wednesday, March 17, 2004 9:40 AM said: No, the value still is not incrementing. then you must be resetting it unknowingly or the else block in your if..else statement is not being executed like you are expecting it to be. one thing i do to debug this kind of thing is to add some echo statements to the different code blocks to see what's happening. for example: if($expression) { echo here i am!; blow_up_world(); } else { echo y hello thar!; eat_cheese(); } then when i execute the page i know what i am expecting and i can compare that to what i am *actually* getting. for example, if i am expecting to see here i am! but instead i see y hello thar! i can know that something is going wrong with my expression. hth, chris. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Simple: Whats wrong with this?
I didn't post it, I just added on to someone elses question. I do use counter++; in other scripts, but it's only in my timesheet app that it doesn't work. It's very odd, so I just made them all $counter = $counter + 1; I didn't have time to mess with it. Was just asking. $counter is initially set to 0, then after a mysql_query(), in the while loop for mysql_fetch_array I was trying $counter++; like I do in my other scripts. But in this case, it didn't work. I just wanted to see if anyone knew why. I'll try the pre increment. Maybe that'll work. It wasn't a big deal, as long as it worked. Jake - Original Message - From: Adam Voigt [EMAIL PROTECTED] To: Shane McBride [EMAIL PROTECTED] Cc: PHP [EMAIL PROTECTED] Sent: Wednesday, March 17, 2004 12:05 PM Subject: RE: [PHP] Simple: Whats wrong with this? Well I accidentally deleted your original email, but I didn't see where you were getting the counter variable from. Where is the variable being stored? You do know that setting $counter++ for one visitor, doesn't translate the value of $counter to another, right? Does this always work? In my timesheet app, I have to do $counter = $counter + 1, because for some reason the $counter++; doesn't work. It just doesn't work, no incrementation of the variable. Is there something in php.ini that can prohibit this from working? Thanks, Jake -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php