在BPM应用程序中,我试图循环关联数组的关联数组,并使用foreach循环仅返回值(APP_UIDs)。但是,我只能显示最后生成的值而不是所有值。
这是我的代码:
$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')
关于我做错了什么的想法?
答案 0 :(得分: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 = '';
来“重新初始化字符串”。
答案 1 :(得分: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)");
}
答案 2 :(得分:0)
更改
foreach($subcases as $subcase)
$subCaseId = $subcase["APP_UID"] . ", ";
到:
$subCaseId = '';
foreach($subcases as $subcase)
$subCaseId .= $subcase["APP_UID"] . ", ";
请注意连接.=