Re: If statement duplicating mysql records?

From: Date: Thu, 21 Jun 2007 20:36:34 +0000
Subject: Re: If statement duplicating mysql records?
References: 1 2 3 4 5 6 7 8 9 10  Groups: php.general 
Request: Send a blank email to php-general+get-257617@lists.php.net to get a copy of this message
Jason Pruim wrote:
On Jun 21, 2007, at 1:58 PM, Roberto Mansfield wrote:
Jason Pruim wrote:
It's not quite making sense to me though... My understanding of IF statements is if the condition is met it ignores all the other if's. Is that not correct? At this point it's just me trying to figure things out for my knowledge :)
No, that's not how it works. If the condition is met, the contents of the if block are executed. If not, and there is an ELSE block, those commands are executed. Then, the script continues after the whole if/then/else structure. Maybe you are thinking of an IF/ELSEIF/ELSEIF/.../ELSE structure? if ( $row[5] == "Level1" ) { // your commands } elseif ( $row[5] == "Level2" ) { // your commands } else { // your commands } This would work in the way you are thinking. Hope this helps your understanding.
Hi Roberto, Thanks for pointing that out, I think it looks better then having a bunch of related if statements with an else at the end anyway. :) Always helps when you use the right tools for the job! :)
well, the right tool for the job is a matter of choice. Maybe I want to use a switch statement instead. switch($row[5]) { case 'Level1': // Your code break; case 'Level2': // Your code break; default: // if none of the case statements above match, then this will be used break; } Just another way to complete the same task
--Roberto Mansfield Institutional Research and Application Development (IRAD) SAS Computing
--PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
-- Jim Lucas "Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them." Twelfth Night, Act II, Scene V by William Shakespeare

« previous php.general (#257617) next »