doulan8330 2016-04-25 14:48
浏览 5
已采纳

在PHP内部划分。 网上商店缩略图

I'm creating a webshop sort of thing without paying. I want to create things like thumbnails, so you can see how a product is called and how it looks like. this is what the thumbnail looks like atm. enter image description here

I use this code to create this:

<div class="product">
        <?php
          include 'assets/php_includes/db_connection.php';

          $query = "SELECT * FROM artikelen";
          $result = mysqli_query($DB_CONNECTION, $query);

          if ($result === false) {
            die(mysql_error());
          }

          while($artikel = mysqli_fetch_array($result)) {
            if ($artikel['Ingeschakeld'] === 1) {
              echo "" . $artikel['Naam'] . "<br>";
              echo "" . $artikel['Prijs'] . "<br>";
              echo "" . $artikel['Informatie'] . "<br>";
              echo "" . $artikel['Ingeschakeld'] . "<br>";
            } else {
              echo "This article isn't available!";
            }
          }
        ?>
      </div>

But all the different items come in 1 thumbnail. How would I make it so it would make multiple thumbnails with only 1 code like this?

  • 写回答

1条回答 默认 最新

  • dongxun2903 2016-04-25 15:29
    关注

    Try like below. Just an example.

    <style>
    .product{
    
        border: 2px solid #808080;
        width: 205px;
        height: 205px;
        margin: 5px;
        padding: 5px;
        border-radius: 5px;
        float: left;
    }
    </style>
    <?php
                $artikel = array(array('Naam'=>"Naam 1", "Prijs"=>"Prijs 1", "Informatie"=>"Informatie 1", "Ingeschakeld"=>1),
                                   array('Naam'=>"Naam 2", "Prijs"=>"Prijs 2", "Informatie"=>"Informatie 2", "Ingeschakeld"=>1),
                                   array('Naam'=>"Naam 3", "Prijs"=>"Prijs 3", "Informatie"=>"Informatie 3", "Ingeschakeld"=>2),
                                   array('Naam'=>"Naam 4", "Prijs"=>"Prijs 4", "Informatie"=>"Informatie 4", "Ingeschakeld"=>1),
                                   array('Naam'=>"Naam 5", "Prijs"=>"Prijs 5", "Informatie"=>"Informatie 5", "Ingeschakeld"=>1),
                                  );
    
                    foreach($artikel as $artikel)
                        {
    
                            ?>
                            <div class="product">
                                <?php
                             if ($artikel['Ingeschakeld'] === 1) {      
                                      echo "" . $artikel['Naam'] . "<br>";
                                      echo "" . $artikel['Prijs'] . "<br>";
                                      echo "" . $artikel['Informatie'] . "<br>";
                                      echo "" . $artikel['Ingeschakeld'] . "<br>";
                                } else {
                                    echo "This article isn't available!";
                                }  
                                ?>
                            </div>
    
                        <?php
                        }
    
    ?>                  
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 QT6颜色选择对话框显示不完整
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下