Re: If statement duplicating mysql records?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux