2014-09-19 73 views
0

我从多个表中调用信息以给出结果作为模板中的变量。模板函数并不是所有相关的,但获得数组和计数正确的是我似乎正在努力解决的问题。如果有人可以请检查代码,我肯定错过了一些东西。多个数组加入

的$ brandFieldArray tableFields包含tableB的字段的信息。例如,如果tableB有一个名为images的字段,tableB中的字段将包含图像的路径,但tableFields将在字段中保存名称“image”以及字段类型,长度,宽度,质量,可见等。的形象。

我可以很容易地创建域,但没有一个数组,但该系统可以创建需要被添加到阵列中,而不必每次都编辑代码字段。

所以我需要调用从tableFields领域和tableB的内容。 tableItems的$结果是为了确保我从tableB获取正确的内容,以保存tableItems中的正确项目。

你能帮我修复这段代码吗?

<?php 
    switch ($requiredVar) { 
     case "brand": 
      $brandFieldsArray = $dbA->query("select * from tableFields where type='X' and visible=1"); 
      $result = $dbA->query("select bID from tableItems where iID = $x"); 
      if ($dbA->count($result) != null) { 
       $thisrecord = $dbA->fetch($result); 
       $bID = $thisrecord["bID"]; 
      } 
      else { 
       $bID = null; 
      } 
      $theBrandsArray = $dbA->query("select * from tableB where bID=$bID"); 
      $bcCount = count($theBrandsArray); 
      $brandContentArray = null; 
      foreach ((array) $theBrandsArray as $brandContent) { 
        $allBrandFields = "";  
        if (is_array($brandFieldsArray)) { 
         $cc = count($brandFieldsArray); 
         foreach ($brandFieldsArray as $brField) { 
         $thisBrandField = $brField; 
         switch ($thisBrandField["fieldtype"]) { 
           case "TEXT": 
           case "TEXTAREA": 
           case "IMAGE": 
           if ($thisBrandField["fieldtype"] == "IMAGE") { 
            if ($brandContent["brandfield".$brField["fieldname"]] == "") { 
             $thisBrandField["content"] = $brfield["defaultimage"]; 
            } 
            else { 
             $thisBrandField["content"] = $brandContent["brandfield".$brField["fieldname"]]; 
            } 
            $thisField = generateImageVariables($brField["x"],$brField["y"]); 
            $thisBrandField["style"] = $thisField["style"]; 
            $thisBrandField["stylefull"] = $thisField["stylefull"]; 
           } 
           else { 
            $brandContent["brandfield".$brField["fieldname"]] = findCorrectLanguage($brandContent,"brandfield".$brField["fieldname"]); 
            if (retrieveOption("convertToBR") == 1 && retrieveOption("WYSIWYGEnabled") == 0) { 
             $thisBrandField["content"] = str_replace("\r\n","<br/>",$brandContent["brandfield".$brField["fieldname"]]); 
            } 
            else { 
              $thisBrandField["content"] = $brandContent["brandfield".$brField["fieldname"]]; 
            } 
           } 
           break; 
          } 
          $brandContent[$brField["fieldname"]] = @$thisBrandField; 
         } 
         if (is_array($allBrandFields)) { 
          $brandContent["brandfields"] = $allBrandFields; 
         } 
         else { 
          $brandContent["brandfields"] = null; 
         } 
        } 
        $brandContentArray[] = $brandContent; 
      } 
      return (count($brandContentArray) == 1 ? $brandContentArray[0] : $brandContentArray); 
    } 
    $tpl->addVariable("brand",$brandContentArray); 
    break; 
?> 
+0

请解释'$ dbA-> retrieveAllRecordsFromQuery()'。我不熟悉那个电话。我自己使用'mysqli'。它使用'$ query_result = $ db-> query()'和'if($ query_result-> num_rows> 0)'。 – PHPglue 2014-09-19 02:05:33

+0

@PHPglue老实说,我无法解释它,因为我从系统中提取类似的查询并重新使用它。做这件事情需要什么,对我来说没问题。 mysqli查询很好。 – user3814045 2014-09-19 03:04:47

+0

您可以在单独的安全'.php'页面上添加'function db(){return new mysqli('host','username','password','database_name');}'。我们将它称为'connect.php'。接下来,在你将使用的页面上包含'folder/connect.php';'。然后就像'$ db = db(); $ sel = $ db-> query('SELECT * FROM table_name WHERE column_name = value'); if($ sel-> num_rows> 0){while($ row = $ sel-> fetch_object()){echo“

{$row->column_name}
{$row->another_column}
”;}} else {echo'No Rows';}'。 – PHPglue 2014-09-19 20:18:37

回答

0

我从来没有在返回时看到过带冒号的构造。也许你可以解释。或者也许它修复了这个问题。

  return $brandContentArray[0] : $brandContentArray; 

删除此行。休息之前,你不能从案子内退回。你有一个以下的命令行。

 // commented out: return $brandContentArray[0] : $brandContentArray; 
} 
$tpl->addVariable("brand",$brandContentArray); 
break; 

您的描述缺少重要信息:数组中必须返回哪些数据?

+0

来自tableFields和tableB的数据应该返回到数组中。应该根据字段名称调用数据。以上并没有解决它的问题,但可能是解决方案的一部分。 – user3814045 2014-09-19 13:08:13

+0

返回的数组必须使用哪种确切格式?在模板 - – 2014-09-19 13:49:04

+0

返回示例呼叫<:brand.fieldname.type:当量:#IF TEXT#> {brand.fieldname.content}或在这样的循环\t \t \t \t \t <#LOOP:brand.extrafields#> 的<#if:brand.brandfields.content:NEQ:空白#> 的<#if:brand.brandfields.type:当量:TEXT#> {brand.brandfields。内容} user3814045 2014-09-19 14:30:21

0

经过进一步寻找到的结构设置与我相信这是使我想它的方向这一工作没有真正的路表的方式。所以我决定只进行单独的呼叫,并将多个阵列留在它之外。

谢谢大家的帮助。