0

在 BPM 应用程序中,我试图遍历关联数组的关联数组,并使用 foreach 循环仅返回值 (APP_UID)。但是,我只能显示最后生成的值,而不是所有值。

这是我的代码:

$currentUser = @@USER_LOGGED;
//Copy Notes to Subprocess
$caseId = @@APPLICATION; //Case UID
$subcases = executeQuery("SELECT APP_UID FROM SUB_APPLICATION WHERE APP_PARENT='$caseId'");
if (is_array($subcases) and count($subcases) > 0) { 
  foreach($subcases as $subcase)
  $subCaseId = $subcase["APP_UID"] . ", ";

//Update the Sent By status
executeQuery("UPDATE APP_CACHE_VIEW SET PREVIOUS_USR_UID = '$currentUser' WHERE APP_UID IN ('$subCaseId')");
}

executeQuery 函数应该生成如下所示的 SQL 语句,但事实并非如此。例子:

UPDATE APP_CACHE_VIEW SET PREVIOUS_USR_UID = '54454572356235' WHERE APP_UID IN      
('336545547', '436545534', '736545125')

关于我做错了什么的任何想法?

4

3 回答 3

3

试试这个。

    $currentUser = @@USER_LOGGED;
    //Copy Notes to Subprocess
    $caseId = @@APPLICATION; //Case UID
    $subcases = executeQuery("SELECT APP_UID FROM SUB_APPLICATION WHERE APP_PARENT='$caseId'");
    if (is_array($subcases) and count($subcases) > 0) { 
      $subCaseId = '';
      foreach($subcases as $subcase)
      $subCaseId .= $subcase["APP_UID"] . ", ";

    //Update the Sent By status
    executeQuery("UPDATE APP_CACHE_VIEW SET PREVIOUS_USR_UID = '$currentUser' WHERE APP_UID IN ('$subCaseId')");
    }

也不要忘记通过$subCaseId = '';在代码中执行“重新初始化字符串”。

于 2013-02-25T04:42:40.183 回答
1

我认为您在这里缺少连接:

在循环顶部初始化变量,如下所示:

$subCaseId = '';

并使用连接运算符.=如下:

$subCaseId .= $subcase["APP_UID"] . ", ";

理想情况下,您还应该从变量中删除最后一个命令和空格$subCaseId

您还需要删除此变量周围的单引号以进行 IN 查询。

请参阅以下完整解决方案:

$currentUser = @@USER_LOGGED;
//Copy Notes to Subprocess
$caseId = @@APPLICATION; //Case UID
$subcases = executeQuery("SELECT APP_UID FROM SUB_APPLICATION WHERE APP_PARENT='$caseId'");
if (is_array($subcases) and count($subcases) > 0) { 
    $subCaseId = '';
      foreach($subcases as $subcase)
          $subCaseId = $subcase["APP_UID"] . ", ";
    //To remove last comma and space
    $subCaseId = substr($subCaseId,0,-2);

//Update the Sent By status
executeQuery("UPDATE APP_CACHE_VIEW SET PREVIOUS_USR_UID = '$currentUser' WHERE APP_UID IN ($subCaseId)");
}
于 2013-02-25T04:42:13.923 回答
0

改变

 foreach($subcases as $subcase)
  $subCaseId = $subcase["APP_UID"] . ", ";

到 :

  $subCaseId = '';
  foreach($subcases as $subcase)
  $subCaseId .= $subcase["APP_UID"] . ", ";

注意串联.=

于 2013-02-25T04:41:10.690 回答