360 网格 -- 完成奇数条记录的行

发布于 2024-10-27 11:10:38 字数 1036 浏览 6 评论 0原文

我正在尝试使用 360 网格系统来完成此任务:https://i.sstatic.net/gL8lk .jpg

从数据库中我得到的产品将按行显示,每行 4 个。

如果每个类别下正好有 4 个产品,那么它工作得很好,但如果一个类别中的产品少于 4 个,则设计会很混乱,因为 div 没有正确关闭。 问题是有时一条生产线上只有 3 种或更少的产品。

你们中有人知道如何实现这一目标吗?

for($i=0 ; $i<$countprod ; $i++){

    $prevprod = $products[$i-1]['name'];
    $curprod = $products[$i]['name'];
    if($curprod != $prevprod){
        echo '<div class="grid_12 alpha omega"><h2>'.$products[$i]['catname'].'</h2></div>';
    }


    if ($i == 0){ echo '<div class="grid_3 '; }
        if ($i % 4 == 0) { echo ' alpha">'; }
        elseif($i % 4 == 3) { echo '</div><div class="grid_3 omega">'; }
        else{ echo '</div><div class="grid_3">';
    }

        echo $product[$i]['image'];

    if ($i % 4 == 3) {
        echo '</div><div class="clear"></div>';
        echo '<div class="grid_3';
    }

}

(抱歉,我不知道如何称呼这个问题:))

I'm trying to accomplish this, with the 360 grid system: https://i.sstatic.net/gL8lk.jpg

From a database i'm getting products which will be displayed in lines with 4 on each.

It's working perfectly if there is exactly 4 products under each category, but if there is less than 4 products in a category, the design is messed up, because the div's not closed properly.
Problem is that sometimes there's only 3 or less products on a line.

Is there any of you who knows how to accomplish this?

for($i=0 ; $i<$countprod ; $i++){

    $prevprod = $products[$i-1]['name'];
    $curprod = $products[$i]['name'];
    if($curprod != $prevprod){
        echo '<div class="grid_12 alpha omega"><h2>'.$products[$i]['catname'].'</h2></div>';
    }


    if ($i == 0){ echo '<div class="grid_3 '; }
        if ($i % 4 == 0) { echo ' alpha">'; }
        elseif($i % 4 == 3) { echo '</div><div class="grid_3 omega">'; }
        else{ echo '</div><div class="grid_3">';
    }

        echo $product[$i]['image'];

    if ($i % 4 == 3) {
        echo '</div><div class="clear"></div>';
        echo '<div class="grid_3';
    }

}

(sorry about the title, i didnt know what to call this question :) )

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

时光瘦了 2024-11-03 11:10:38
echo '<div class="grid_3';

您没有关闭此标签。

echo '<div class="grid_3';

You aren't closing this tag.

路弥 2024-11-03 11:10:38

尝试一下

$countprod = count($product);
$prevprod = '';
$close_div = false;
for ($i=0; $i<$countprod; $i++){

    $curprod = $products[$i]['name'];
    if($curprod != $prevprod){
        if ($close_div) echo '</div>';
        echo '<div class="grid_12 alpha omega"><h2>'.$products[$i]['catname'].'</h2></div>';
    }

    if ($i % 4 == 0) { 
        echo '<div class="grid_3 alpha">';
        $close_div = true;
    }
    elseif ($i % 4 == 3) {
        echo '</div><div class="grid_3 omega">';
        $close_div = true;
    }
    else { 
        echo '</div><div class="grid_3">';
        $close_div = true;
    }

    echo $product[$i]['image'];

    if ($i % 4 == 3) {
        echo '</div><div class="clear"></div>';
        $close_div = false;
    }
    $prevprod = $curprod;
}

Have a try with

$countprod = count($product);
$prevprod = '';
$close_div = false;
for ($i=0; $i<$countprod; $i++){

    $curprod = $products[$i]['name'];
    if($curprod != $prevprod){
        if ($close_div) echo '</div>';
        echo '<div class="grid_12 alpha omega"><h2>'.$products[$i]['catname'].'</h2></div>';
    }

    if ($i % 4 == 0) { 
        echo '<div class="grid_3 alpha">';
        $close_div = true;
    }
    elseif ($i % 4 == 3) {
        echo '</div><div class="grid_3 omega">';
        $close_div = true;
    }
    else { 
        echo '</div><div class="grid_3">';
        $close_div = true;
    }

    echo $product[$i]['image'];

    if ($i % 4 == 3) {
        echo '</div><div class="clear"></div>';
        $close_div = false;
    }
    $prevprod = $curprod;
}
两个我 2024-11-03 11:10:38
$p = 10; // Current number of products

$ppr = 4; // Products per row
$x = $i % $ppr;

if($x != 0){
    $countprod = $p + ($ppr - $x);
}

echo $countprod; // 12 (4 * 3)

如果没有产品,则使用 FOR 循环,只需打印空 DIV,如果这就是您所要求的......

$p = 10; // Current number of products

$ppr = 4; // Products per row
$x = $i % $ppr;

if($x != 0){
    $countprod = $p + ($ppr - $x);
}

echo $countprod; // 12 (4 * 3)

Loop with FOR if there is no product just print empty DIV, if that's what you have asked...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文