Page 1 of 1

switch statments

Posted: Wed Jun 02, 2004 2:33 am
by n8w
Hello .. I was able to do this in VB so .. I am sure I can do it in PHP .... anyway how do you write an if else statement or switch statment so you accomplish the following

Code: Select all

<? if statment is true?> 

tons of html code

<? else ?> 

tons more of different html code

<? endif?>

Posted: Wed Jun 02, 2004 2:53 am
by CoderGoblin

Code: Select all

if ($var == "xyz") &#123;
  // tons of code or call to function
  echo($htmlcode);
&#125; else &#123;
  // tons of different code or function
  echo ($htmlcode);
&#125;
Basic PHP. Switch is used for an if then elseif ... structure (CASE I believe in VB).

Regards

Posted: Wed Jun 02, 2004 3:05 am
by patrikG
[php_man]switch[/php_man]

one more question

Posted: Wed Jun 02, 2004 3:09 am
by n8w
thanks for replying

I tried something similar to what you wrote .. but I am getting a parsing error .. I think because I am trying to dynamically write other stuff as well

basically what I would like to do is

Code: Select all

<?php
$tempdog=$_GET&#1111;'id']; 
$length=strlen($tempdog);
if ( $length > 0 ) &#123;


==========================
write this code
==========================
<body onLoad="MM_preloadImages('images/<? echo $_GET&#1111;'id']; ?>-m.gif','images/<? echo $_GET&#1111;'id']; ?>-l.gif')">

 &#125; else &#123;
==========================
write this code
==========================
<body>
&#125;

?>

Posted: Wed Jun 02, 2004 11:39 am
by launchcode
You need to break out of your code, but essentially what you want to do will work fine - but before all the "=== write this code" stuff, break out of PHP first.

Posted: Wed Jun 02, 2004 12:40 pm
by jason

Code: Select all

<?php if ( $something_is_true ) : ?>
...lots of HTML....
<?php else: ?>
...lots of HTML....
<?php endif; ?>
I find using that method nice when mixing PHP with HTML. The endif; is clearer than a }, because with a } you don't know what it's being used for without some checking. The endif; makes it clear. So if you are mixing a few block level elements like a foreach, a while and an if, it makes reading easier.