Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 是否仅显示阵列中具有匹配ID的结果?_Php_Joomla - Fatal编程技术网

Php 是否仅显示阵列中具有匹配ID的结果?

Php 是否仅显示阵列中具有匹配ID的结果?,php,joomla,Php,Joomla,编辑:问题已经解决 我必须在第一个查询中使用loadColumn,并将数组更改为$results。这就是全部!很高兴它现在起作用了。感谢所有的答案:我将在页面底部发布更新的代码 ----------------------------------------------------------------- 我想根据具有挂起值的状态字段显示数据库中的一些值。假设我在我的网站上提交了一份表格。它的SubmissionId为50。因此,Container1、Status1、Date1、BayanNo

编辑:问题已经解决

我必须在第一个查询中使用loadColumn,并将数组更改为$results。这就是全部!很高兴它现在起作用了。感谢所有的答案:我将在页面底部发布更新的代码

-----------------------------------------------------------------

我想根据具有挂起值的状态字段显示数据库中的一些值。假设我在我的网站上提交了一份表格。它的SubmissionId为50。因此,Container1、Status1、Date1、BayanNo1等多个值都可以具有相同的SubmissionId

以下是我编写的代码,但在运行页面时未加载:

<?php 

    $db = JFactory::getDbo();
    $db->getQuery(true);

    $db->setQuery("SELECT `SubmissionId` FROM `jos_rsform_submission_values` WHERE `FieldName` = \"Status1\" AND `FieldValue` = \"Pending\"");
    $results = $db->loadObjectList();

    //First query which gets the SubmissionId where "Status" is "Pending"
    //Trying to add these SubmissionId's into an array (don't know if correct or not)
    $arr = [$results];

    //Second query which must display the ContainerNumber based on SubmissionId (Some values are from the same form that the user submitted, that is why the Status and ContainerNumber have the same SubmissionId

    $db->getQuery(true);
    $db->setQuery("SELECT `SubmissionId`, `FieldValue` FROM `jos_rsform_submission_values` WHERE `FieldName` = \"Container1\" AND `SubmissionId` IN '" .$arr. "' "); 

    $result = $db->loadObjectList();

    foreach($result as $value) {
        foreach($value as $key => $data) { 
          echo $data."<br />"; 
       }
   }
?>
以下是更新后的工作代码:


尝试使用php中的in_数组。我希望它能解决您的问题。

SQL中in的语法是:select*from foo,其中bar位于'1','2','3'


代码使用数组映射引用您的数组,并在in表达式中使用它。

您已尝试打印\u r$result或尝试调试所有数组我尚未尝试打印\u r$result,但我现在会这样做。当我打印\u$result或$arr时,它会给我一个值。现在您选中此选项只返回匹配的值或不返回匹配的值。第二个打印\r$result只给我一个值值数组;而print_r$arr为我提供了正确的值。第二个查询肯定有问题。您希望我在何处将每个$result的in_arrayforeach添加为$value{在这个循环中,您可以在in_array中使用。
<?php 

    $db = JFactory::getDbo();
    $db->getQuery(true);

    $db->setQuery("SELECT `SubmissionId`, `FieldValue` FROM `jos_rsform_submission_values` WHERE `FieldName` = \"Status1\" AND `FieldValue` = \"Pending\"");

    $results = $db->loadColumn();

    //First query which gets the SubmissionId where "Status" is "Pending"

    //Second query which must display the ContainerNumber based on SubmissionId 

    $db->getQuery(true);
    $db->setQuery("SELECT `FieldValue` FROM `jos_rsform_submission_values` WHERE `FieldName` = \"Container1\" AND `SubmissionId` IN ('".implode("', '", $results)."') ORDER BY `jos_rsform_submission_values`.`SubmissionId`"); 

    $result = $db->loadObjectList();
    foreach($result as $value) {
        foreach($value as $key => $data) { 
          echo $data."<br />"; 
       }
   }
?>
$db = JFactory::getDbo();
$db->getQuery(true);

$db->setQuery("SELECT `SubmissionId` FROM `jos_rsform_submission_values` WHERE `FieldName` = \"Status1\" AND `FieldValue` = \"Pending\"");
$results = $db->loadObjectList();

//First query which gets the SubmissionId where "Status" is "Pending"
//Trying to add these SubmissionId's into an array (don't know if correct or not)

$arr = array_map($db->quote, $results));
//Second query which must display the ContainerNumber based on SubmissionId (Some values are from the same form that the user submitted, that is why the Status and ContainerNumber have the same SubmissionId

$db->getQuery(true);
$db->setQuery("SELECT `SubmissionId`, `FieldValue` FROM `jos_rsform_submission_values` WHERE `FieldName` = \"Container1\" AND `SubmissionId` IN (" .implode(',', $arr). ") "); 

$result = $db->loadObjectList();

foreach($result as $value) {
    foreach($value as $key => $data) { 
      echo $data."<br />"; 
   }
}