Jump to content

if statements


Th3Boss
Go to solution Solved by PaulRyan,

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?

Edited by Th3Boss
Link to comment
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.

Edited by Th3Boss
Link to comment
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
Share on other sites

  • Solution

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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.