如何为我在 php 中使用 while 循环显示的每个图像添加不同的 CSS 设计

How to add different CSS design to every image that I display using while loop in php

任何人都可以帮助我如何将不同的 CSS 设计应用到使用 PHP 中的 while 循环显示的图像。我想知道是否可以在从数据库中获取的每张图像中应用不同的设计。

<?php

 $new = $_GET['id'];                         

 $imageResult = mysqli_query($db,"SELECT * FROM postimage ORDER BY post_id = '$new'  LIMIT 5");

 while( $imageRow = mysqli_fetch_array($imageResult)){

     echo "
         <div class='col-md-6 main-box' id='clickme'>
             <img class='box1 image-gallery' src='../img_upload/".$imageRow['name']."'' style='object-fit:cover;'>
         </div>";

 }
?>

This is the code I use in displaying my image from my database This is what I get on my website

This is how I want to display my image(I can apply css design on every image to resize and adjust their position )

note: this image was stored in my database using join table so this was fetch and display using the same id (which is my post_id). I really appreciate any help from you guys thank you so much in advance

您可以为特定的 class 添加索引,并基于此您可以正确查看该图像 .image-1 { ... your CSS }

<?php

 $new = $_GET['id'];
             
                      

                    $imageResult = mysqli_query($db,"SELECT * FROM postimage ORDER BY post_id = '$new'  LIMIT 5");
                
                       $count = 0;
                       while( $imageRow = mysqli_fetch_array($imageResult)){
                          $count++;
                          echo "

                            <div class='col-md-6 main-box image-".$coun."' id='clickme'>

                                <img class='box1 image-gallery' src='../img_upload/".$imageRow['name']."''
                                    style='object-fit:cover;'>

                            </div>";
                    }
                
                    ?>