Php 如何在每4次使用“继续”时分割
如何设置产品类别与限制4这就是为什么我必须拆分,而循环与每4计数 我想要这样的东西: 类别名称1Php 如何在每4次使用“继续”时分割,php,Php,如何设置产品类别与限制4这就是为什么我必须拆分,而循环与每4计数 我想要这样的东西: 类别名称1 产品1 产品2 产品3 产品4 类别名称2 产品5 产品6 产品7 产品8 我尝试了以下代码: $count=0; while($row_pt = $result_2->fetch_array()) { if($count%4==0) { $output .= ' <div class="col-sm-4 col-
- 产品1
- 产品2
- 产品3
- 产品4
- 产品5
- 产品6
- 产品7
- 产品8
$count=0;
while($row_pt = $result_2->fetch_array())
{
if($count%4==0)
{
$output .= '
<div class="col-sm-4 col-lg-3 col-md-3">
<h3>CATEGORY NAME'.$row_pt['cat_id'].'</h3>
<div style="border:1px solid #ccc; border-radius:0px; padding:16px; margin-bottom:16px; height:250px;">
<img src="image/'. $row_pt['product_image'] .'" alt="" class="img-responsive" >
<p align="center"><strong><a href="#">'. $row_pt['product_name'] .'</a></strong></p>
Course Code : '. $row_pt['product_name'] .' <br />
Course Name : '. $row_pt['product_name'] .' <br />
</div>
</div>';
continue;
}
$count++;
}
$count=0;
而($row\u pt=$result\u 2->fetch\u array())
{
如果($count%4==0)
{
$output.='
类别名称“.$row\U pt['cat\U id']”
课程代码:'.$row\U pt['product\U name'].
课程名称:'.$row\U pt['product\U Name'].
';
继续;
}
$count++;
}
类似于此,因此您使用count变量将每四种产品包装在一个div中:
$count = 1;
while ($row_pt = $result_2->fetch_array())
{
if (($count - 1) % 4 === 0)
{
$output .= '<div class="products">';
}
$output .=
'<h3>CATEGORY NAME' . $row_pt['cat_id'] . '</h3>
<div class="product">
<img src="image/' . $row_pt['product_image'] . '">
<a href="#">' . $row_pt['product_name'] . '</a>
<span>Course Code : ' . $row_pt['product_name'] . '</span>
<span>Course Name : ' . $row_pt['product_name'] . '</span>
</div>';
if ($count % 4 === 0)
{
$output .= '</div>';
}
$count++;
}
if (($count - 1) % 4 !== 0)
{
$output .= '</div>';
}
$count=1;
而($row\u pt=$result\u 2->fetch\u array())
{
如果(($count-1)%4==0)
{
$output.='';
}
$output.=
“类别名称”。$row\U pt[“类别id]”
课程代码:'.$row\U pt['product\U name'].'
课程名称:'.$row\U pt['product\U Name'.'
';
如果($count%4==0)
{
$output.='';
}
$count++;
}
如果(($count-1)%4!==0)
{
$output.='';
}
类似于此,因此您使用count变量将每四种产品包装在一个div中:
$count = 1;
while ($row_pt = $result_2->fetch_array())
{
if (($count - 1) % 4 === 0)
{
$output .= '<div class="products">';
}
$output .=
'<h3>CATEGORY NAME' . $row_pt['cat_id'] . '</h3>
<div class="product">
<img src="image/' . $row_pt['product_image'] . '">
<a href="#">' . $row_pt['product_name'] . '</a>
<span>Course Code : ' . $row_pt['product_name'] . '</span>
<span>Course Name : ' . $row_pt['product_name'] . '</span>
</div>';
if ($count % 4 === 0)
{
$output .= '</div>';
}
$count++;
}
if (($count - 1) % 4 !== 0)
{
$output .= '</div>';
}
$count=1;
而($row\u pt=$result\u 2->fetch\u array())
{
如果(($count-1)%4==0)
{
$output.='';
}
$output.=
“类别名称”。$row\U pt[“类别id]”
课程代码:'.$row\U pt['product\U name'].'
课程名称:'.$row\U pt['product\U Name'.'
';
如果($count%4==0)
{
$output.='';
}
$count++;
}
如果(($count-1)%4!==0)
{
$output.='';
}
请,1)格式化您的代码,这是一个混乱,2)提供一个,您提供的代码对除您以外的任何人都不起作用。请显示您得到的@Tejas输出当我按cat_id 2进行筛选时,它没有拆分如果您希望具有限制4
,为什么您的示例有cat 1
:3产品,CAT 2
:4个产品?请,1)格式化您的代码,这是一个混乱,2)提供一个,您提供的代码对您以外的任何人都不起作用。请显示您在@Tejas时获得的输出。当我按CAT_id 2进行筛选时,它没有拆分如果您希望限制为4
,为什么您的示例有CAT 1
:3个产品,CAT 2
:4个产品?我没有测试它,但它不是在:0、10、15、20、25、30启动div,然后在:4、8、12、16、20、24、28等关闭div。
我建议在启动新的div时关闭div,所以将第一个if语句分开。我建议编辑我的意思。对不起@Kerwinsneinders你是对的,我已经更新了我的答案。没关系,可能会发生。看起来不错!虽然当以4的倍数结束时,它不会以一个opendiv
结束吗?这可能会破坏页面的其余部分,或者我遗漏了什么?或者,当不是以4的倍数结束时,它也不会关闭当前的div
,对吗?现在看不到任何问题。我没有测试这个,但这不会在以下位置启动div:0,10,15,20,25,30
,然后在以下位置关闭div:4,8,12,16,20,24,28等等。
我建议在启动新的div时关闭div,因此将第一个if语句分开。我建议编辑我的意思。对不起@Kerwinsneinders你是对的,我已经更新了我的答案。没关系,可能会发生。看起来不错!虽然当以4的倍数结束时,它不会以一个opendiv
结束吗?这可能会破坏页面的其余部分,或者我遗漏了什么?或者,如果不是以4的倍数结束,它也不会关闭当前的div
,对吗?现在看不到任何问题。