为了账号安全,请及时绑定邮箱和手机立即绑定

在 IF PHP 中嵌入引导程序容器

在 IF PHP 中嵌入引导程序容器

PHP
慕田峪7331174 2023-03-26 14:48:43
首先,我尝试了几乎所有类似问题的解决方案,但我无法得到结果。我正在尝试更换设计以显示一些数据。我已将产品列表存储在$prods = array()因此,当我尝试让这些产品改变它们在网页上的显示方式时,我做了如下操作:$aux = count($prods);foreach($prods as $key => $value):?><?php if($aux%2 == 0): ?><html>    <div class="container">        <div class="row justify-content-around my-3">            <figure class="col-6 figure my-3 row justify-content-center">                <img style="height: 20vw" src="imagenes/d3.jpeg" class="figure-img img-fluid rounded" alt="...">            </figure>            <div class="col-6 row justify-content-around">                <div class="col row align-items-center">                    <div class="col display-3"><?php $value ?></div>                    <div class="col-12 display-5">Lorem ipsum dolor sit amet consectetur adipisicing elit. Aperiam saepe ipsum quod nesciunt labore magni a perspiciatis sunt officia facere, reprehenderit praesentium explicabo ipsa eligendi! Cumque nulla reiciendis perferendis sequi.</div>                    <p class="col-12 lead">Precio: Lorem, ipsum dolor.</p>                </div>            </div>        </div>    </div></html><?php $aux = $aux-1; ?><?php else: ?><html>    <div class="container">        <div class="row justify-content-around my-3">            <div class="col-6 row justify-content-around">            <div class="col row align-items-center">                    <div class="col-12 display-3"><?php $value ?></div>                    <div class="col-12 display-5">Lorem ipsum dolor sit amet consectetur adipisicing elit. Aperiam saepe ipsum quod nesciunt labore magni a perspiciatis sunt officia facere, reprehenderit praesentium explicabo ipsa eligendi! Cumque nulla reiciendis perferendis sequi.</div>                <p class="col-12 lead">Precio: Lorem, ipsum dolor.</p>                </div>            </div>        </div>    </div></html><?php $aux = $aux-1; ?><?php endforeach;?>当我运行它时只得到空白结果。没有html代码。我是 PHP/HTML/MongoDB 的新手,所以我正在努力学习!感谢您。
查看完整描述

1 回答

?
冉冉说

TA贡献1877条经验 获得超1个赞

通常如果你的$prod不为空,这应该有效:


<?php

$aux = count($prods);

?>

<html>

<body>


<?php

foreach($prods as $key => $value){

    if($aux%2 == 0){ ?>

        <div class="container">

            <div class="row justify-content-around my-3">

                <figure class="col-6 figure my-3 row justify-content-center">

                    <img style="height: 20vw" src="imagenes/d3.jpeg" class="figure-img img-fluid rounded" alt="...">

                </figure>

                <div class="col-6 row justify-content-around">

                    <div class="col row align-items-center">

                        <div class="col display-3"><?php $value ?></div>

                        <div class="col-12 display-5">Lorem ipsum dolor sit amet consectetur adipisicing elit. Aperiam saepe ipsum quod nesciunt labore magni a perspiciatis sunt officia facere, reprehenderit praesentium explicabo ipsa eligendi! Cumque nulla reiciendis perferendis sequi.</div>

                        <p class="col-12 lead">Precio: Lorem, ipsum dolor.</p>

                    </div>

                </div>

            </div>

        </div>

        <?php $aux = $aux-1; } else {?>


        <div class="container">

            <div class="row justify-content-around my-3">

                <div class="col-6 row justify-content-around">

                    <div class="col row align-items-center">

                        <div class="col-12 display-3"><?php $value ?></div>

                        <div class="col-12 display-5">Lorem ipsum dolor sit amet consectetur adipisicing elit. Aperiam saepe ipsum quod nesciunt labore magni a perspiciatis sunt officia facere, reprehenderit praesentium explicabo ipsa eligendi! Cumque nulla reiciendis perferendis sequi.</div>

                        <p class="col-12 lead">Precio: Lorem, ipsum dolor.</p>

                    </div>

                </div>


                <figure class="col-6 figure my-3 row justify-content-center">

                    <img style="height: 20vw" src="imagenes/d.jpeg" class="figure-img img-fluid rounded" alt="...">

                </figure>


            </div>

        </div>

        <?php $aux = $aux-1; ?>


    <?php }};?>


</body>


</html>



查看完整回答
反对 回复 2023-03-26
  • 1 回答
  • 0 关注
  • 97 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信