【问题标题】:When I fetch data from mysql database it create new row every time instead of single row当我从 mysql 数据库中获取数据时,它每次都会创建新行而不是单行
【发布时间】:2021-04-12 11:17:49
【问题描述】:

每次都创建新行,而不是创建四张卡片。我使用小 3 列,我想在一行中列出 4 张卡片,并像在电子商务网站中一样从数据库中获取数据

<div class="row container bg-light">
<?php 
while ($result=mysqli_fetch_assoc($link)) {
    echo "<a href='com.php?id=$result[id]' style='text-decoration:none;'>";
        echo "<div class='col-sm-3 bg-white border  rounded shadow'>";
            echo "<div class='bg- m-2 text-center'>";
                echo "<img src='adeolu-eletu-DXYyKCCvWiM-unsplash.jpg' alt='' class='w-75 h-75' >";
                echo "<h3 class=''>$result[name]</h3>";
                echo "<h6 class=''>$result[discription]</h6>";
                echo "<h2 class='text-danger link'>Rs $result[price]</h2>";
                echo "<Button class='btn bg-success '>Order</button>";
                echo "<Button class='btn bg-danger '>Add to Cart</button>";
            echo "</div>";
        echo "</div>";
    echo "</a>";
    echo print_r($result);
}
?>
</div>

【问题讨论】:

标签: php html twitter-bootstrap


【解决方案1】:

Bootstrap 要求列是行的子级。

您正在为列使用 div 元素,但将其包装为锚元素,然后将该锚元素作为该行的子元素。

要么将锚点放在 div 中,要么首先将锚点作为列。

...你的行也需要在一个容器中,而不是它们本身的容器。

<link rel=stylesheet href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<div class="container">
   <div class="row bg-light">
      <a href='com.php?id=$result[id]' style='text-decoration:none; ' class='col-sm-3 bg-white border  rounded shadow'>
         <div class='bg- m-2 text-center'>
            <h3 class=''>$result[name]</h3>
            <h6 class=''>$result[discription]</h6>
            <h2 class='text-danger link'>Rs $result[price]</h2>
            <Button class='btn bg-success '>Order</button>
            <Button class='btn bg-danger '>Add to Cart</button>
         </div>
      </a>
      <a href='com.php?id=$result[id]' style='text-decoration:none; ' class='col-sm-3 bg-white border  rounded shadow'>
         <div class='bg- m-2 text-center'>
            <h3 class=''>$result[name]</h3>
            <h6 class=''>$result[discription]</h6>
            <h2 class='text-danger link'>Rs $result[price]</h2>
            <Button class='btn bg-success '>Order</button>
            <Button class='btn bg-danger '>Add to Cart</button>
         </div>
      </a>
      <a href='com.php?id=$result[id]' style='text-decoration:none; ' class='col-sm-3 bg-white border  rounded shadow'>
         <div class='bg- m-2 text-center'>
            <h3 class=''>$result[name]</h3>
            <h6 class=''>$result[discription]</h6>
            <h2 class='text-danger link'>Rs $result[price]</h2>
            <Button class='btn bg-success '>Order</button>
            <Button class='btn bg-danger '>Add to Cart</button>
         </div>
      </a>
      <a href='com.php?id=$result[id]' style='text-decoration:none; ' class='col-sm-3 bg-white border  rounded shadow'>
         <div class='bg- m-2 text-center'>
            <h3 class=''>$result[name]</h3>
            <h6 class=''>$result[discription]</h6>
            <h2 class='text-danger link'>Rs $result[price]</h2>
            <Button class='btn bg-success '>Order</button>
            <Button class='btn bg-danger '>Add to Cart</button>
         </div>
      </a>
   </div>
</div>

【讨论】:

  • 它可以工作,但问题是我如何设置卡片的边距
猜你喜欢
  • 2017-07-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多