Python社区  »  DATABASE

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

Seekerz • 1 周前 • 22 次点击  

我有一个用于autoparts的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.
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/56748
 
22 次点击  
分享到微博
文章 [ 1 ]  |  最新文章 1 周前
andreah
Reply   •   1 楼
andreah    10 月前

如果我理解正确:

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

使用:

<a target="_blank" href="<?php echo $product_array[$key]["msimage"]; ?>"><img src="<?php echo $product_array[$key]["msimage"]; ?>" class="imgcartdisplay" align="alignnone"/></a>

或者。。。如果你是说这样的话 https://lokeshdhakar.com/projects/lightbox2/#examples 必须使用javascript(例如: <a href="images/image-1.jpg" data-lightbox="image-1" data-title="My caption">Image #1</a>

在您的例子中,类似于这样:(当然,您需要添加lightbox脚本: https://lokeshdhakar.com/projects/lightbox2/#getting-started )

<a data-lightbox="image-1" data-title="My caption" href="<?php echo $product_array[$key]["msimage"]; ?>"><img src="<?php echo $product_array[$key]["msimage"]; ?>" class="imgcartdisplay" align="alignnone"/></a>