Php 在HTML中的MySQL表数据中,每行显示4项
我正在开发一个web应用程序,可以显示MySQL数据库中的项目 这是我当前的代码:Php 在HTML中的MySQL表数据中,每行显示4项,php,html,Php,Html,我正在开发一个web应用程序,可以显示MySQL数据库中的项目 这是我当前的代码: $conn = mysqli_connect($db_host, $db_user, $db_pass, $db_name); if (!$conn) { die ('Failed to connect to MySQL: ' . mysqli_connect_error()); } mysqli_set_charset($conn, "utf8"); $sql = 'SELECT * FROM t
$conn = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
if (!$conn) {
die ('Failed to connect to MySQL: ' . mysqli_connect_error());
}
mysqli_set_charset($conn, "utf8");
$sql = 'SELECT * FROM tb_tiendas';
$query = mysqli_query($conn, $sql);
?>
<!-- Content
============================================= -->
<section id="content">
<div class="content-wrap">
<div class="container clearfix">
<div class="col-xl-10" style="display: flex; justify-content: center;">
<?php
$i = 0;
$num_tiendas = mysqli_num_rows($query);
$path = "/administrar/application/admin/tiendas/";
while ($row = mysqli_fetch_array($query))
{
$foto = $row['imagen'];
$nombre = $row['nombre'];
$direccion = $row['direccion'];
$horario = $row['horario'];
?>
<div class="col-md-4">
<td><img width="280" height="200" src="<?php echo $path.$foto ?>"/></td>
<h4><?php echo $nombre ?></h4>
<h5><?php echo $direccion ?></h5>
<h6><?php echo $horario ?></h6>
</div>
<?php
$i++;
}
?>
</div>
</div>
</div>
</section>
$conn=mysqli\u connect($db\u host、$db\u user、$db\u pass、$db\u name);
如果(!$conn){
die('未能连接到MySQL:'。mysqli_connect_error());
}
mysqli_set_charset($conn,“utf8”);
$sql='SELECT*FROM tb_tiendas';
$query=mysqli\u query($conn,$sql);
?>
"/>
我需要的是每行显示4个项目
如何每4个项目插入一行新的项目?如果您使用的是Bootstrap 4,则有一个名为
.row
的类,在该类中,您将项目放入div
中,并使用.col
类名,请参见:
。。。。
....
了解有关bootstrap 4网格系统的更多信息如果您使用bootstrap 4,则有一个名为
.row
的类,在该类中,您可以将项目放入带有.col
类名的div
,请参阅:
。。。。
....
了解有关bootstrap 4网格系统的更多信息在每次迭代中使用计数器并检查其值。在每次迭代中使用计数器并检查其值。