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 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)