Jump to content

if statements


Th3Boss

Recommended Posts

This is how I currently have it setup

 

<?php if ($high1name == "open") { ?>

<div class="module high open">
    <img src="Icon_hi_slot.png" width="46" height="46">
</div>

<?php } elseif ($high1name == "none") { ?>

    <div class="module high inactive">

    </div>

<?php } else { ?>

<div class="module high">
    <img src="http://image.website.com/Type/<?php print($high1typeID);?>_64.png">
    
</div>


<? } ?>
 

 

 

But I would like to have it something like this

 

 

<?php if ($high1name == "open") { ?>

<div class="module high open">
    <img src="Icon_hi_slot.png" width="46" height="46">
</div>

<?php } elseif ($high1name == "ANY VALUE HERE") { ?>

<div class="module high">
    <img src="http://image.website.com/Type/<?php print($high1typeID);?>_64.png">
    
    </div>

<?php } else { ?>

<div class="module high inactive">
    
</div>


<? } ?>
 

 

How do I get the elseif to work for any value $high1name has?

Link to comment
https://forums.phpfreaks.com/topic/276045-if-statements/
Share on other sites

Actually I just found out about switch statements and this seems to do what I want

 

 


<?php if ($high7name == "") {
?>
<div class="module high inactive">
    </div>
<? } else { ?>


<?
switch ($high7name) {
case "none":
?>
<div class="module high inactive">
    </div>
<? break;?>
<?
case "open":
?>
<div class="module high open">
    <img src="Icon_hi_slot.png" width="46" height="46">
</div>
<? break;?>
<?
default:
?>

<div class="module high">
    <img src="http://image.website.com/Type/<?php print($high7typeID);?>_64.png">
</div>
<? } ?>
<? } ?>

 

Not sure if that is the best way to write it or not but currently it is working as I want it to.

Link to comment
https://forums.phpfreaks.com/topic/276045-if-statements/#findComment-1420487
Share on other sites

ok and it seems this does the same thing but as an if statement

 

<?php if ($high1name == "open") { ?>

<div class="module high open">
    <img src="Icon_hi_slot.png" width="46" height="46">
</div>

<?php } elseif ($high1name == "") { ?>

    <div class="module high inactive" >

    </div>

<?php } else { ?>

<div class="module high" data-typeid=$high1typeID data-name=$high1name>
    <img src="http://image.website.com/Type/<?php print($high1typeID);?>_64.png">
    
</div>


<? } ?>
 
Link to comment
https://forums.phpfreaks.com/topic/276045-if-statements/#findComment-1420488
Share on other sites

You shouldn't jump in and out of PHP tags like that, it makes for messy code.

 

Try this:

 

<?PHP

  if($highname1 == 'open') {
    $output = '<div class="module high open">
                 <img src="Icon_hi_slot.png" width="46" height="46">
               </div>';
  } else if(strlen(trim($highname1))) {      
    $output = '<div class="module high inactive">
               </div>';
  } else {      
    $output = '<div class="module high" data-typeid=$high1typeID data-name=$high1name>
                 <img src="http://image.website.com/Type/'. $high1typeID .'_64.png">
               </div>';
  }
 
  echo $output;
 
?>
Link to comment
https://forums.phpfreaks.com/topic/276045-if-statements/#findComment-1420492
Share on other sites

 

You shouldn't jump in and out of PHP tags like that, it makes for messy code.

 

Try this:

 

<?PHP

  if($highname1 == 'open') {
    $output = '<div class="module high open">
                 <img src="Icon_hi_slot.png" width="46" height="46">
               </div>';
  } else if(strlen(trim($highname1))) {      
    $output = '<div class="module high inactive">
               </div>';
  } else {      
    $output = '<div class="module high" data-typeid=$high1typeID data-name=$high1name>
                 <img src="http://image.website.com/Type/'. $high1typeID .'_64.png">
               </div>';
  }
 
  echo $output;
 
?>

 

 

That worked though they were switched around. Works as wanted like this:

 

 

<?PHP

  if($high2name == 'open') {
    $output = '<div class="module high open">
                 <img src="Icon_hi_slot.png" width="46" height="46">
               </div>';
  } else if(strlen(trim($high2name))) {      
    $output = '<div class="module high" data-typeid=$high2typeID data-name=$high2name>
                 <img src="http://image.website.com/Type/'. $high2typeID .'_64.png">
               </div>';
  } else {      
    $output = '<div class="module high inactive">
               </div>';
  }
 
  echo $output;
 
?>
 

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/276045-if-statements/#findComment-1420496
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.