我正在运行查询以从搜索页上的数据库恢复产品。这是我想做的事:如何使用foreach获得forloop工作
我想一些文本放置6和每一页上的18个分页结果的12后。
如果搜索运行不到12个结果回来,我想告诉我如何在工作后的6只
文字我的环我的foreach内?
这是我的代码。代码应该放在哪里?
为:
@for ($i = 0; $i < count($products); $i++)
@if (in_array($i,array(6,12,18)) && count($products) >= 12)
<h2> example code </h2>
@elseif ($i == 6 && count($products) < 12)
<h2>example</h2>
@endif
@endfor
的foreach:
@foreach ($products as $product)
<div class="row sing">
<div class="col-md-3">
<a href="{{route('products.single',$product->slug)}}"><div class="img"><div class=" container img-s" style="background-image:url('{{ asset('images/' . $product->image)}}'); background-repeat: no-repeat;
background-size: cover;
background-position: center center;"></div></div></a>
</div>
<div class="col-md-9">
<div class="info-productsearch">
<div class="name-holder">
<h4>{{$product->productname}}</h4>
@if(Count($product->reviews) >0)
<p>Rated : {{number_format($product->reviews->avg('ratings'),2)}}/ 5, from {{$product->reviews->count()}} reviews</p>
@else
<p>Rated : Yet To Be Reviewed</p>
@endif
</div>
<p class="location-det"><i class="icon-map-marker"></i> {{$productt->producttypes}}, {{$sight->productrefcode}}</p>
<p>{{substr(strip_tags($product->prodinfo), 0, 325)}}<a class="find-out-more" href="{{route('products.single',$product->slug)}}"> (...Find out more)</a></p>
</div>
</div>
</div>
@endforeach
试过,我得到其他如果但不是如果。奇怪的一个作为其他如果显示7个产品之后不是6 – detinu20
不工作我得到的是第7个产品之后的示例代码。这是错误的,因为它应该在6和12之后,除非它们小于12,结果应该在6之后。我对此的理解不是很好,但是In_array和其他Array在做之后关闭了什么,因为它似乎被忽略了? – detinu20