通过回声自动从 mysql 检索许多图像并在单击时放大它们

我有一个用于汽车零件的 PhP 购物车,我需要能够在单击它时放大检索到的图像。问题是我无法为每张图片手动分配 ID,因为我正在从数据库中回显它们。


我已经尝试为所有检索到的图片分配一个 ID/类,并使用 JS 功能在单击时放大它们,但无法使其正常工作。


    $items_array = $db_controller->runQuery("SELECT * FROM mystuff ORDER BY ID ASC");

    if (!empty($items_array)) { 

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

    ?>


            <div class="DisplayCartItems">


            <form method="post" action="?action=add&mscode=<?php echo $product_array[$key]["mscode"]; ?>">

            <img src="<?php echo $product_array[$key]["msimage"]; ?>" class="imgcartdisplay" align="alignnone"/> /* Right here I need some help */

            <div class="lif"><strong>Category:</strong> <?php echo $product_array[$key]["mscategory"]; ?></div>

            <div class="lif"><strong>Category №:</strong> <?php echo $product_array[$key]["mscatnum"]; ?></div>

            <div class="lif"><strong>Stock №:</strong> <?php echo $product_array[$key]["msnomer"]; ?></div> 

            <div class="lif"><strong>Mark:</strong> <?php echo $product_array[$key]["msmark"]; ?></div>

            <div class="lif"><strong>Model:</strong> <?php echo $product_array[$key]["msmodel"]; ?></div>

            <div class="lif"><strong>Year:</strong> <?php echo $product_array[$key]["msyear"]; ?></div>

            <div class="lif"><strong>Price:</strong> <?php echo "$".$product_array[$key]["msprice"]; ?></div>

            <div style="text-align:center"><input type="number" name="oap" placeholder="Offer a price:"></div>

            <br class="">


            <div class="cartan">

                Quantity: <input type="text" class="product-quantity" name="quantity" value="1" size="2" />


                <br class="">

                <input type="submit" onclick="AddCartAlert()" value="Add to cart" /></div>


    </form>

                </div>

    <?php

        }

    }

    ?>```


I think if I can somehow assign an ID or class name for every picture that get displayed from the MySql and onclick change it's width/height, that'd do the job.


狐的传说
浏览 144回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP