我从多个表中调用信息以给出结果作为模板中的变量。模板函数并不是所有相关的,但获得数组和计数正确的是我似乎正在努力解决的问题。如果有人可以请检查代码,我肯定错过了一些东西。多个数组加入
的$ 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;
?>
请解释'$ dbA-> retrieveAllRecordsFromQuery()'。我不熟悉那个电话。我自己使用'mysqli'。它使用'$ query_result = $ db-> query()'和'if($ query_result-> num_rows> 0)'。 – PHPglue 2014-09-19 02:05:33
@PHPglue老实说,我无法解释它,因为我从系统中提取类似的查询并重新使用它。做这件事情需要什么,对我来说没问题。 mysqli查询很好。 – user3814045 2014-09-19 03:04:47
您可以在单独的安全'.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“