doumo3903 2019-05-30 10:25
浏览 126

如何运行1个完整的循环圆而不是刷新页面,而不是检查if(),如果满足条件,则再次运行1个循环圈

What i want is after user click specific button on my webpage, I will check with if(isset()) than run the follow commend for loop.

This is what i have done so far. If $balance is 10 than for loop should run 10 times. For loop run instantly 10 times without refreshing the page but sleep() function help delay it. I need to refresh the page every 1 loop complete than continue the rest 9 loops. Every loop need to refresh page every time its run.

$balance = '10';
$wallet = $_SESSION['wallet'];

if(isset($_POST['click'])){
    if($balance != 0){
        for($x = 0; $x < $balance; $x++){
            $sql = $conn->query("UPDATE wallets SET balance = balance - 1 WHERE wallet = '$wallet' " );
            //some code to complete this 
            ....
            //this is where the page to refresh
            header("location: click.php?e=2");
        }
        sleep(5);
    }
    else{
        header("location: click.php?e=1");
    }
}

What i expected is .... 1 loop complete refresh page 1 time than continue another 1 loop than refresh page 1 more time than continue....

  • 写回答

1条回答 默认 最新

  • drwo32555 2019-05-30 10:30
    关注

    You don't need any loop its just decrement values will work.

    $balance = ($_SESSION['balance'] ?? 0);
    $wallet  = $_SESSION['wallet'];
    if (isset($_POST['click'])) {
        if ($balance > 0) {
            // for ($x = 0; $x < $balance; $x++) {
            $sql                = $conn->query("UPDATE wallets SET balance = balance - 1 WHERE wallet = '$wallet' ");
            $_SESSION['wallet'] = intval($_SESSION['wallet']) - 1;
            $_SESSION['balance'] = $_SESSION['balance']-1;
            //some code to complete this
            //....
            //this is where the page to refresh
            header("location: click.php?e=2");
            // }
            sleep(5);
        } else {
            header("location: click.php?e=1");
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 arduino控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题