Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
223 views
in Technique[技术] by (71.8m points)

php - When I fetch data from mysql database it create new row every time instead of single row

instead of creating four card it create new row every time. I use column small 3, i want 4 card listed in one row and fetch data from database as in ecommerce websites

<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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Bootstrap requires that columns be children of rows.

You are using a div element for your columns, but are wrapping it an anchor element and then making that anchor a child of the row.

Either put the anchor inside the div, or make the anchor the column in the first place.

… your rows need to be in a container too, not a container in their own right.

<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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...