Are you first timer at lazacode.org? Why not join us and start exchange your programming knowledge with everyone. Register today!

PHP - if, else, elseif condition

0 votes
77 views
added Mar 27 in PHP by LC Marshal Lieutenant (13,570 points)
edited Jul 20 by LC Marshal
// If $bedrooms is not empty, show the .hidden-t-m elements

<?php if (!empty($bedrooms)): ?>
    <div class="hidden-t-m"><?php print $bedrooms ?> Beds</div> 
<?php endif; ?>

 

18 Responses

0 votes
responded Apr 16 by LC Marshal Lieutenant (13,570 points)
edited Jul 20 by LC Marshal
// If value has no character or null

<?php if ($row['authname']==0): ?>
    <span class="show-anon">Anonymous</span>
<?php endif; ?>

 

0 votes
responded Apr 18 by LC Marshal Lieutenant (13,570 points)
edited Jul 20 by LC Marshal
// If value is not null

<?php if (!empty($title)): ?>
    <h1 class="page-header"><?php print $title; ?></h1>
<?php endif; ?>

 

0 votes
responded Apr 20 by LC Marshal Lieutenant (13,570 points)
edited Jul 20 by LC Marshal
// If empty

<?php if (empty($row['name'])): ?>
    Anonymous
<?php endif; ?>

 

0 votes
responded Apr 24 by LC Marshal Lieutenant (13,570 points)
edited Jul 20 by LC Marshal
// Check if value is exist

<?php
$os = array("Mac", "NT", "Irix", "Linux");
if (in_array("Irix", $os)) {
    echo "Got Irix";
}
if (in_array("mac", $os)) {
    echo "Got mac";
}
?>

 

0 votes
responded Apr 24 by LC Marshal Lieutenant (13,570 points)
edited Jul 20 by LC Marshal
// If value available only rental and room_rental, show Rent, else show  $specific_type = $field_prop_listing_type

<?php
  if ( ($field_prop_listing_type == 'rental') ||  ($field_prop_listing_type == 'room_rental') )
  {
    $specific_type = "Rent";
  }
  else
  $specific_type = $field_prop_listing_type;
  ?>
  <?php print 'For ' . $specific_type; 
?>

 

0 votes
responded Apr 24 by LC Marshal Lieutenant (13,570 points)
edited Jul 20 by LC Marshal
// Condition for time 

<?php
$t = date("H");

if ($t < "10") {
    echo "Have a good morning!";
} elseif ($t < "20") {
    echo "Have a good day!";
} else {
    echo "Have a good night!";
}
?>

 

0 votes
responded Apr 24 by LC Marshal Lieutenant (13,570 points)
edited Jul 20 by LC Marshal
<!--Condition over condition-->
<div class="extended-stats hidden-m">
    <?php if (!empty($la_ppu)):?>
     <?php print 'RM ' . $la_ppu . ' psf';?>
   <?php else:?>
     <?php if ($node->field_prop_listing_type->und[0]->value !== 'rental'): ?>
       <span class="est-mort"> 
          <span class="value"></span>/mth
        </span>
      <?php endif; ?>   
    <?php endif;?>
</div>
0 votes
responded Apr 24 by LC Marshal Lieutenant (13,570 points)
edited Jul 20 by LC Marshal
//Hide if value !== 'thisValue"
<?php if ($node->field_prop_listing_type->und[0]->value !== 'rental'):?>
<div class="calculator" onclick="jQuery('.mortgage-calculator').toggleClass('hidden')">
    <i class="fa fa-calculator" aria-hidden="true"></i>
    <i class="fa fa-angle-down" aria-hidden="true"></i>
</div>
<?php endif;?>
0 votes
responded May 3 by LC Marshal Lieutenant (13,570 points)
edited Jul 20 by LC Marshal
// If user is login, show this. Else show this

<div class="search-box-area">
  <h2>Got A Property Question? Get Answers Here, or</h2>
  <?php if(isset($user->roles[1]) ) { ?>
  <div id="forum-ask-btn-sign-in"><a class="btn btn-xs btn-success" href="?showlogin=true">Sign In to Ask a Question</a></div> 
  <?php } else { ?>
  <div id="forum-ask-btn"></div>
  <?php } ?>
</div>

 

0 votes
responded May 22 by LC Marshal Lieutenant (13,570 points)
edited Jul 20 by LC Marshal
// If more transaction use transactions, else use transaction

<?php print $totalTras; echo ($totalTras != '1') ? ' Transactions' : ' Transaction'; ?>

 

0 votes
responded Jun 4 by LC Marshal Lieutenant (13,570 points)
edited Jul 20 by LC Marshal
// If value is bigger than 0 only show

<?php if ($bedrooms > 1): ?>
    <div id="no-zero" class="prop-rooms"><?php print $bedrooms ?> Bed</div>
<?php else: ?>
  <!-- shows nothing -->
<?php endif; ?>

 

0 votes
responded Jun 4 by LC Marshal Lieutenant (13,570 points)
edited Jul 20 by LC Marshal
<?php if ($bedrooms > 0): ?>
    <div class="prop-rooms"><?php print $bedrooms ?> Bed</div>
<?php else: ?>
    <!-- shows nothing -->
<?php endif; ?>
0 votes
responded Jun 28 by LC Marshal Lieutenant (13,570 points)
edited Jul 20 by LC Marshal
<?php /**grammar condition /***/ ?>
<?php print $count ?>&nbsp;&nbsp;<?php print $count > 1 ? 'Units': 'Unit' ?>
0 votes
responded Jul 23 by LC Marshal Lieutenant (13,570 points)
//Show data or row
<?php if(!empty($profile->field_is_miid_registered->value())): ?> 
<?php if(!empty($data['field_is_miid_registered'])): ?> 
<?php if(!empty($row['field_is_miid_registered'])): ?>

 

0 votes
responded Aug 13 by LC Marshal Lieutenant (13,570 points)
<div class="p-card">
  <?php if($slink):?>
  <a href="<?php print $row['path']; ?>" title="<?php print $name; ?>">
    <?php endif;?>
    <div class="p-card-image">
      <?php print $image; ?>
      <div class="p-card-status <?php
                if($status==3):
                  echo 'p-card-status--fund';
                else:
                  echo 'p-card-status--buy'; // green
                endif;
                ?>">
        <?php print $status_title;?>
      </div>
    </div>
    <div class="p-card-info">
      <div class="detail name">
        <?php print $name; ?>
      </div>
      <div class="detail location">
        <?php print $add1;
         print (substr(trim($add1),-1) != ',')?', ':'';
         print $state; ?>
      </div>
      <div class="jc--sb w-100">
        <div>
          <div class="detail">
            <div class="units">
              <?php print $count ?>
              <?php print $count > 1 ? 'Units': 'Unit' ?>
            </div>
            <div class="movein">
              <?php print $row['move'];?>
            </div>

          </div>
          <ul class="list-room">
            <?php if(isset($row['bed'])):?>
            <li>
              <img class="icon" src="/sites/all/themes/mytheme/assets/icon/bed.svg" alt="bedroom" /> <?php print $row['bed'];?>
            </li>
          <?php endif;
                if(isset($row['bath'])):
           ?>
            <li>
              <img class="icon" src="/sites/all/themes/mytheme/assets/icon/bath.svg" alt="bathroom" /> <?php print $row['bath'];?>
            </li>
          <?php endif;
                if(isset($row['car'])):
           ?>
            <li>
              <img class="icon" src="/sites/all/themes/mytheme/assets/icon/parking.svg" alt="carpark" /> <?php print $row['car'];?>
            </li>
          <?php endif;
                if(isset($row['size'])):
           ?>
            <li>
              <img class="icon" src="/sites/all/themes/mytheme/assets/icon/area.svg" alt="area" /> <?php print $row['size'];?>
            </li>
          <?php endif;?>
          </ul>
        </div>
      </div>
    </div>
    <div class="p-card-info market">
      <div class="market-price">Market Price: From RM
        <?php print number_format($markval); ?>
      </div>
    </div>
    <div class="p-card-info">
      <div class="pay-to-own">
        <?php if($action == 'buy'):?>
        <p class="text-bold">Pay to Own:</p>
        <p>From RM <?php print number_format($cost_to_own); ?></p>
        <?php else:?>
          <p class="text-bold">Funding Target:</p>
          <p>From RM <?php print number_format($f_target); ?></p>
        <?php endif;?>
      </div>
    </div> 
    <div class="more-info">
      <button class="button">View This Property</button>
    </div>
    <!-- <div class="offer">
               Early Bird Incentive - Get up to 5% discount when U purchase now
           </div> -->
    <?php if($slink):?>
  </a>
  <?php endif;?>
</div>

 

0 votes
responded Aug 14 by LC Marshal Lieutenant (13,570 points)
// if its for buy, show this otherwise..
<div class="listing-batch">
  <?php if($unit_ops == 'buy'):?>
    Buy Now
  <?php else:?>
    Invest Now
  <?php endif; ?>
</div>

 

0 votes
responded Aug 17 by LC Marshal Lieutenant (13,570 points)
<ul class="list-unstyled multi-steps">
    <?php if($show_tools || $show_buy):?>
    <li class="fa processing <?php echo ($p_stage == 1)?'is-active':''; ?>">
      <span class="steps-label">Awaiting Payment</span>
    </li>
    <li class="fa booked <?php echo ($stage == 5)?'is-active':''; ?>">
      <span class="steps-label">Reserved by Buyer</span>
    </li>
  <?php endif;?>
    <li class="fa investing <?php echo ($stage == 2)?'is-active':''; ?>">
      <!-- <span class="shape-badge"></span> -->
      <span class="steps-label">Funding Now</span>
    </li>
    <li class="fa s-p <?php echo ($stage == 6)?'is-active':''; ?>">
      <span class="steps-label">S & P</span>
    </li>
    <li class="fa stamping <?php echo ($stage == 7)?'is-active':''; ?>">
      <span class="steps-label">Stamping Completed</span>
    </li>
    <li class="fa vp <?php echo ($stage == 8)?'is-active':''; ?>">
      <span class="steps-label">VP</span>
    </li>
</ul>

 

0 votes
responded Sep 7 by LC Marshal Lieutenant (13,570 points)
<?php if($params['act'] == 'buy'): ?>
<div class="quiries text-center text-small">
    *After you’ve secured the booking with a payment, you will have 2 weeks to pay the balance (refer to amount under ‘Remaining left’).
</div>
<?php else:?>

<div class="quiries text-center text-small">
    *Once the funding target is achieved, you will be asked to sign relevant agreements within 5 working days.
</div>
<?php endif; ?>

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...