我设置了一个新的网站,我想显示在盒子的检索库MySQLi查询的结果。
我的PHP代码....
$query = mysqli_query($con,"SELECT * FROM `products`");
while($row = mysqli_fetch_array($query)) {
echo "<img src='/Images/".$row['product_image']."' height='200' width='200'>"
echo '<h6> Id:'.$row['product_id'].'</h6>';
echo '<h6> Name:'.$row['product_name'].'</h6>';
echo '<h6> Proce:'.$row['product_price'].'</h6>';
}
与代码搜索查询的结果都这样
我用很多方法使用达到的结果类似这样的介绍努力:
任何想法或建议?谢谢
使用CSS“浮动:左”
$query = mysqli_query($con,"SELECT * FROM `products`");
while($row = mysqli_fetch_array($query)) {
echo '<div style="float:left">';
echo "<img src='/Images/".$row['product_image']."' height='200' width='200'>";
echo '<h6> Id:'.$row['product_id'].'</h6>';
echo '<h6> Name:'.$row['product_name'].'</h6>';
echo '<h6> Proce:'.$row['product_price'].'</h6>';
echo '</div>';
}
您可以使用引导程序来实现这一目标。例如,只需添加类=“山坳LG-4”在div标签内,你将不得不为每行3列。
示例代码:
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<script src="https://code.jquery.com/jquery-latest.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<section class="content">
<div class="container">
<div class="row">
<?php
$get = mysqli_query($con, "SELECT * FROM `products` ORDER BY `product_name`");
while ($products = mysqli_fetch_assoc($get)) { ?>
<div class="col-lg-4">
<div class="thumbnail" align="center">
<img src="admin/images/products/<?php echo $products['photo']; ?>" style="width: 220px; height: 150px">
<div class="caption">
<h4>
<?php echo $products['product_name']; ?>
</h4>
<span>$<?php echo number_format($products['price']); ?></span>
<br />
<br />
<a href="index.php?data=detail&i=<?php echo $products['id']; ?>" class="btn btn-primary">Detail</a>
<input type="button" name="wishlist" id="add_wishlist" value="+ " onclick="addWishlist('<?php echo $products[id]; ?>', '<?php echo $id_user; ?>')" class="btn btn-info">
</div>
</div>
</div>
<?php } ?>
</div>
</div>
</section>