简体   繁体   中英

PHP hits counter

Im having a problem with a php script. I want to make it work so when under 5 hits it shows a locked button and greater than 5 hits it shows a unlocked button.

<?
 if($hits < 5){
    ?>
   <div id="status-button-locked"></div>

    <?  
  }
  ?>

<?

 if($hits > 5){
    ?>
   <div id="status-button-unlocked"></div>

    <?  
  }
  ?>

I have tried the code above but it didn't work, when it is greater than 5 it just wont show anything.

It won't show anything, when 5 hits exactly. Try:

<?
 if($hits < 5){
    ?>
   <div id="status-button-locked"></div>
    <?  
  } else {
  ?>
   <div id="status-button-unlocked"></div>
  <?  
  }
  ?>

Like David said it now doesn't react when it hits exactly 5.

Try this:

<?php
  if($hits >= 5){  // this part happens if $hits is 5 or higher.
?>
   <div id="status-button-unlocked"></div>
<?php 
  } else {
?>
   <div id="status-button-locked"></div>    
<?php 
  } 
?>

this way you handle errors like when $hits is empty.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM