单个事件PHP脚本



我正在建立一张收银员将进入美元金额的表格。当他们输入该美元金额时,将为他们的帐户增加100点,以每花费每一美元。这是在WordPress上构建的,因此您会看到我会使用Update_user_meta((获得并更新此点值。和get_user_meta((;内置在WordPress中。

当用户达到不同的点级别时,您会看到我有一堆IF语句发射。我的问题是,我如何才能使这些陈述仅在第一次超过点门槛时出现?

<form method="post" action="">
$<input type="text" name="value">
<input type="submit">
</form>
<?php
$prev_total = get_user_meta(get_current_user_id(), mycred_default, true);
$add_total = (floor($_POST['value']) * 100);
$now_total = $prev_total + $add_total;
update_user_meta(get_current_user_id(), mycred_default, $now_total);
echo get_user_meta(get_current_user_id(), mycred_default, true);
if($now_total > 0 && $now_total < 2501){
    echo "<h2>Customer Get's A Free Small Cup or Cone of Custard: Next Level 5000 Points.</h2>";
} elseif($now_total > 4999 && $now_total < 7500){
    echo "<h2>Customer Get's A Free Medium Gelato: Next Level 7500 Points.</h2>";
} elseif($now_total > 7499 && $now_total < 10000){
    echo "<h2>Customer Get's A Free Brownie Blackout: Next Level 10,000 Points.</h2>";
} elseif($now_total > 9999 && $now_total < 15000){
    echo "<h2>Customer Get's A Free Large Milk Shake: Next Level 15,000 Points.</h2>";
} elseif($now_total > 14999 && $now_total < 20000){
    echo "<h2>Customer Get's A Free Pint of Custard: Next Level 20,000 Points.</h2>";
} elseif($now_total > 19999 && $now_total < 25000){
    echo "<h2>Customer Get's A Free Pint of Custard: Next Level 25,000 Points.</h2>";
} elseif($now_total > 24999 && $now_total < 35000){
    echo "<h2>Customer Get's A Free Round of Mini Golf: Next Level 35,000 Points.</h2>";
} elseif($now_total > 34999 && $now_total < 45000){
    echo "<h2>Customer Get's A Free Small Custard Cake: Next Level 45,000 Points.</h2>";
} elseif($now_total > 44999 && $now_total < 50000){
    echo "<h2>Customer Get's 20 Free Batting Cage Tokens: Next Level 50,000 Points.</h2>";
} elseif($now_total >= 50000){
    echo "<h2>Customer Get's 20 Free Batting Cage Tokens & 20 Free Batting Cage Tokens.</h2>";
    $now_total = 0;
}
?>

使用您的现有代码,我将在elseif的另一个条件中添加另一个条件以检查上一个总数 - 类似于

} elseif($prev_total < 5000 && $now_total > 4999 && $now_total < 7500){

因此,下次他们进行购买时,先前的总价值将在这些限制之内,因此直到下一个限制都不应击中。