我有一个为 Joomla 2.5 和模块的参数中自定义创建的模块,并且有一个未按预期输出的循环。我在模块中有以下参数(字段): Order Thumb image Image Title Full-size image
现在有 10 组这些 4 参数组。我想要做的是循环遍历每个对象集,其中 10 个,并在每次迭代中构建一个 HTML 图像列表结构。
if 语句为 order 值大于 0 的集合构建 HTML 结构,else 为那些值不大于 0 的集合创建 html。
目标是创建两个变量,然后将字符串连接在一起;前导集是定义了顺序的集。这没有发生,每三个循环似乎都丢失了。
这是 10 组中设置的顺序
Set 1 = 0
Set 2 = 4
Set 3 = 1
Set 4 = 0
Set 5 = 5
Set 6 = 0
Set 7 = 0
Set 8 = 6
Set 9 = 3
Set 10 = 9
然而,结果是:
9
5
1
4
6
7
10
而不是预期的:
3
9
2
5
8
1 (below here are those sets that were not greater than 0 in order of appearance)
4
6
7
这里有什么我看不到的问题?
<?php
for ($i = 1; $i <= 10; $i++) {
$order = $params->get('order'.$i);#get order for main loop of 10
$active = "";
if ($order > 0) {#Check if greater than 0
for ($n = 1; $n <= 10; $n++) {#loop through all order fields looking and build html lowest to highest;
$ordercheck =$params->get('order'.$n);
if ($ordercheck == $i) {
$img = $params->get('image'.$n);
$fimage = $params->get('image'.$n.'fullimage');
$title = $params->get('image'.$n.'alttext');
$active = "";
$active = $active . '<li>';
$active = $active . '<a href="'.$fimage.'" rel="prettyPhoto[gallery1]" title="'.$title.'">';
$active = $active . '<img src="'.$img.'" alt="'.$title.'" />';
$active = $active . '</a>';
$active = $active . '</li>';
$leading = $leading . $active;
}
}
} else { #if the itteration $order was not greater than 0, build in order of accourance
$img = $params->get('image'.$i);
$fimage = $params->get('image'.$i.'fullimage');
$title = $params->get('image'.$i.'alttext');
$active = $active . '<li>';
$active = $active . '<a href="'.$fimage.'" rel="prettyPhoto[gallery1]" title="'.$title.'">';
$active = $active . '<img src="'.$img.'" alt="'.$title.'" />';
$active = $active . '</a></li>';
$unordered = $unordered . $active;
}
$imagesList = $leading . $unordered;
}
?>