dpw5865 2019-05-03 10:03
浏览 48

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

So I am running a SQL query via PHP which is returning two rows in an array with two columns "Suppler" and "ViewAll".

I need to get the values per row and check view all is yes so send "Supplier" ID's into a variable to use in another SQL statement.

So the matching statement should be IF "View all" = 1 THEN append Supplier to variable $va for example

I've already tried the below code but can only get it to bring the first row back

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();
    }
}

Just brings back the first row and cant append using .=

SQL will be something like this SELECT * FROM table WHERE supplier = (id1,id2)

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 软件测试决策法疑问求解答
    • ¥15 win11 23H2删除推荐的项目,支持注册表等
    • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
    • ¥15 qt6.6.3 基于百度云的语音识别 不会改
    • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
    • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
    • ¥15 lingo18勾选global solver求解使用的算法
    • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
    • ¥20 测距传感器数据手册i2c
    • ¥15 RPA正常跑,cmd输入cookies跑不出来