在一定量的查询结果后放置文本

时间:2017-08-16 14:38:54

标签: php html laravel

我正在运行查询以在搜索页面上恢复我的数据库中的产品...这是我想要做的:

- 我希望在每页的18个分页结果中的6个和12个之后放置一些文本。

- 如果搜索运行并且返回的结果少于12,我想仅在6之后显示文本

我该怎么做呢?这是我的代码。

HTML:

    @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

我想在上面解释的内容中添加:

<div class="row text-center">
<h2> example</h2>
</div>

2 个答案:

答案 0 :(得分:0)

您必须使用@for循环,例如:

@for ($i = 0; $i < count($products); $i++) @if (in_array($i,array(6,12,18)) && count($products) >= 12) Your action @elseif ($i == 6 && count($products) < 12) Your second action @endif @endfor

如果我正确理解你的问题。

答案 1 :(得分:0)

我没时间检查,但它会像

    @foreach ($products as $product)
        @if (count($products) < 12)
            @for ($i = 0; $i < count($products); $i++)
                @if ($i == 6)
                    <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>
                @endif
             @endfor
        @else
            @for ($i = 0; $i < count($products); $i++)
                @if ($i == 6 || $i ==12)
                    <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>
                @endif
           @endfor
        @endif
@endforeach