循环不能正常工作

时间:2018-02-02 08:02:17

标签: php mysql

以下是我的环境的广泛概述

数据库:

  1. Tsql Database = SysAid
  2. MySql数据库= Bounties
  3. MySql数据库=游戏化
  4. 所以代码的作用是:

    • 管理员在赏金数据库上为SysAid请求加载赏金,如果活动为0,则获取状态1(如果未激活则为0),0为未完成状态。
    • 代码检查并在屏幕上显示赏金(不同代码)
    • 用户通过完成对SysAid的请求来索取赏金
    • 如果请求已完成,代码将检查sysaid,然后更新bounty数据库以表明它已完成并将其标记为非活动状态。

    但是出于某种原因,每次cron运行这段代码来检查赏金是否完成时,即使它仍然不完整,它也会将其标记为非活动状态。

    以下是我的代码,它应检查sysaid上的已关闭状态,然后更新表。但是它只是在没有关闭票证的情况下改变状态。

        <?php
    $servername = "*.*.*.*.";
    $username = "*";
    $password = "*";
    $dbname = "Gamification";
    
    $conn = new mysqli($servername, $username, $password, $dbname);
    if ($conn->connect_error) {
        die("Connection Failed : " . $conn->connect_error);
    }
    
    $sql = "SELECT * FROM performance_bounties";
    $result = $conn->query($sql);
    
    while ($row = $result->fetch_assoc()) {
        $ticket_number = $row['ticket_number'];
        $bounty_value = $row['bounty_value'];
        $bounty_completed = $row['completed'];
        $bounty_completed_by = $row['completed_by'];
        $bounty_enabled = $row['enabled'];
        check_sysaid($ticket_number, $bounty_value, $bounty_completed,     $bounty_completed_by, $bounty_enabled);
    }
    
    
    function check_sysaid($ticket_number, $bounty_value, $bounty_completed, $bounty_completed_by, $bounty_enabled) {
    
        $servername = "*.*.*.*";
        $username = "*";
        $password = "*";
        $dbname = "Gamification";
    
        $conn2 = new mysqli($servername, $username, $password, $dbname);
        if ($conn2->connect_error) {
            die("Connection Failed : " . $conn2->connect_error);
        }
    
        putenv("TDSVER=80");
        putenv("FREETDSCONF=/etc/freetds/freetds.conf");
        putenv("ODBCSYSINI=/etc/odbcinst.ini");
        putenv("ODBCINI=/etc/odbc.ini");
    
    
        $myServer = "TS";
        $username = "*";
        $password = "*";
        $database = "SYSAID";
    
    //connection to the database
        $dbhandle = mssql_connect($myServer, $username, $password)
        or die("Couldn't connect to SQL Server on $myServer");
    
    //select a database to work with
        $selected = mssql_select_db($database, $dbhandle)
        or die("Couldn't open database $myDB");
    
        $sysaidcheckquery = "
      SELECT id, substring(responsibility,11,11) as responsibility, status from service_req where id = '" . $ticket_number . "'";
    
        $sysaidcheckresult = mssql_query($sysaidcheckquery);
        $numRows = mssql_num_rows($sysaidcheckresult);
    
        while ($sysaidrow = mssql_fetch_array($sysaidcheckresult)) {
            echo $ticketstatus;
            $ticketid = $sysaidrow['id'];
            $ticketresponsibility = $sysaidrow['responsibility'];
            $ticketstatus = $sysaidrow['status'];
    
        if ($ticketstatus = "27") {
            $bountysqlupdate = "UPDATE performance_bounties SET enabled = '0', completed = '1', completed_by = '" . $ticketresponsibility . "' WHERE ticket_number = " . $ticket_number;
            $performanceupdate = "UPDATE performance_q3_2018 SET bounties = '" . $bounty_value . "' where user_name = '" . $ticketresponsibility . "'";
    
            if ($conn2->query($bountysqlupdate) === TRUE) {
                echo "Record updated successfully";
            } else {
                echo "Error updating record: " . $conn2->error;
            }
    
            if ($conn2->query($performanceupdate) === TRUE) {
                echo "Record updated successfully";
            } else {
                echo "Error updating record: " . $conn2->error;
            }
        }
    
    
        }
    
    
    
    }
    
    
    
    ?>
    

1 个答案:

答案 0 :(得分:4)

您正在分配(=)而不是比较(==)。

$ticketstatus = "27"

将始终评估为true。它应该是

if ($ticketstatus == "27") {