如何为特定用户仅运行一次if条件?

时间:2018-09-17 22:29:28

标签: php session

session_start();
$result = query("SELECT *FROM users");
confirm($result);

while($row = fetch_assoc($result)){
    $id = $row['userId'];
    $level = $row['level'];
    $rs = query("SELECT *FROM income 
                WHERE user_id = '$id'");
    confirm($rs);
    $inc = fetch_assoc($rs);
    if($level == 2 && !isset($_SESSION['l2'.$id])){
        $cal = $inc['incentive']+170; 
        $_SESSION['l2'.$id] = 1;
        confirm(query("UPDATE income SET incentive='$cal' WHERE user_id='$id'"));
    }else
        if($level == 3 && !isset($_SESSION['l3'.$id])){
            $cal = $inc['incentive']+430; 
            $_SESSION['l3'.$id] = 1;
            confirm(query("UPDATE income SET incentive='$cal' WHERE user_id='$id'"));
        }

有成千上万的用户,在此代码中将创建成千上万的会话,任何人都可以帮助我编写高效的代码。

0 个答案:

没有答案