从PHP数组返回值并将其组合以匹配true或false

时间:2019-05-03 10:03:01

标签: php arrays variables compare

因此,我正在通过PHP运行SQL查询,该查询将返回具有两列"Suppler""ViewAll"的数组中的两行。

我需要获取每行的值,并检查view all是,因此将"Supplier" ID发送到变量中以在另一个SQL语句中使用。

因此匹配的语句应为IF "View all" = 1,然后将“供应商”附加到变量$ va中

我已经尝试了以下代码,但只能将其带回第一行

protected function getAllInidents($c_id) {

    //Getting view all incidents for retilaer
    $contact_id = (int) $c_id;
    // print_r($contact_id);

    try {

        //This query may bring back one row or multiple
        $q1 = RNCPHP\ROQL::query("SELECT * FROM Retail.RetailerContactRel where Contact = {$contact_id}")->next();

        //getting values from returned query
        while ($q1r = $q1->next()) {
            $ret = $q1r['Retailer'];
            $va = $q1r['ViewAllTickets'];
        }
        //This if statemnet should evaluate the results from above and if matched the $ret id(s) needs to be passed to the ROQL statment , there could be many $ret results if there are more than one result
        if ($va != "0") {
            $newIncidentArray = array();
            //First check if contact has logged any tickets yet if not diplsay message and exit
            $roql_result = RNCPHP\ROQL::query("SELECT Incident.ID FROM Incident where Incident.PrimaryContact.Contact=" . $contact_id . " AND Incident.CustomFields.Retail.RetailerDetails is not null")->next();

            if (!empty($roql_result)) {
                //if user has logged tickets retrieve them and also retrieve any retailer tickets where the user has view all tickets for the retailer set to yes
                $roql_result = RNCPHP\ROQL::query(
                    "SELECT Incident.StatusWithType.Status.LookupName as Status, Incident.ID, Incident.customfields.retail.RetailerDetails.RetailerName, LookupName, Subject, Severity, Incident.PrimaryContact.ParentContact.Emails.EmailList.Address AS CreatedByUser, Incident.CreatedTime AS CreatedTime, Incident.ClosedTime AS ClosedTime 
                    FROM Incident 
                    WHERE incident.customfields.retail.RetailerDetails = {$ret} AND Incident.PrimaryContact.ParentContact.Emails.EmailList.Address is not null 
                       OR Incident.PrimaryContact.Contact = {$contact_id} AND Incident.PrimaryContact.ParentContact.Emails.EmailList.Address is not null"
                )->next();

                //changing the date format from unix time staff to a readable front end format
                while ($inc = $roql_result->next()) {
                    if ($inc['CreatedTime']) {
                        $date = $inc['CreatedTime'];
                        $time = strtotime($date);
                        $inc['CreatedTime'] = date("m/d/Y", $time);
                    }
                    if ($inc['ClosedTime']) {
                        $date = $inc['ClosedTime'];
                        $time = strtotime($date);
                        $inc['ClosedTime'] = date("m/d/Y", $time);
                    }
                    $newIncidentArray[] = $inc;
                }
                //returning list of incidents in an array this is then passed to logic.js
                return $newIncidentArray;
            } else {
                return "You don't have any tickets created.";
            }
        } else {
            $newArray = array();
            $newIncidentArray = array();
            $a = 0;
            $roql_result = RNCPHP\ROQL::query(
                "SELECT Incident.ID 
                FROM Incident 
                WHERE Incident.PrimaryContact.Contact=" . $contact_id . " AND Incident.CustomFields.Retail.RetailerDetails is not null"
            )->next();

            if (!empty($roql_result)) {

                //do same here
                $roql_result = RNCPHP\ROQL::query(
                    "SELECT Incident.StatusWithType.Status.LookupName as Status, Incident.ID, Incident.customfields.retail.RetailerDetails.RetailerName, LookupName, Subject, Severity, Incident.PrimaryContact.ParentContact.Emails.EmailList.Address AS CreatedByUser, Incident.CreatedTime AS CreatedTime, Incident.ClosedTime AS ClosedTime 
                    FROM Incident 
                    WHERE Incident.PrimaryContact.Contact = {$contact_id} AND Incident.PrimaryContact.ParentContact.Emails.EmailList.Address is not null"
                )->next();

                while ($inc = $roql_result->next()) {
                    if ($inc['CreatedTime']) {
                        $date = $inc['CreatedTime'];
                        $time = strtotime($date);
                        $inc['CreatedTime'] = date("m/d/Y", $time);
                    }
                    if ($inc['ClosedTime']) {
                        $date = $inc['ClosedTime'];
                        $time = strtotime($date);
                        $inc['ClosedTime'] = date("m/d/Y", $time);
                    }

                    $newIncidentArray[] = $inc;
                }

                return $newIncidentArray;
            } else {
                return "You don't have any tickets created.";
            }
        }
    } catch (Connect\ConnectAPIErrorBase $e) {
        $warnings[] = $e->getMessage();
    }
}

只需带回第一行并不能使用。=

追加

SQL将会是这样的SELECT * FROM table WHERE supplier = (id1,id2)

0 个答案:

没有答案
相关问题