想在同一列中以5行显示图像和文本,但是在所提供的代码中,这并不能满足我的要求,因为当它们显示时,它们以行而不是列显示。感谢您的帮助。
此图像显示了屏幕上当前显示的内容...
我想要的是这个...
<?php
$select_stmt=$db->prepare("SELECT * FROM galeria ORDER BY id DESC;" ); //sql select query
$select_stmt->execute();
while($row=$select_stmt->fetch(PDO::FETCH_ASSOC))
{
?>
<div class="container">
<div class="row">
<div class="col-sm-12">
<div class="col-sm-6"><img src="upload/<?php echo $row['image']; ?>" class="imagem" style="height: 100px; weight: 100px;"></div>
<div class="col-sm-6"><a id=""><?php echo $row['texto'];?></a></div>
</div>
</div>
</div>
<?php
}
?>
答案 0 :(得分:1)
现在它正在工作。感谢大家的帮助。这是下面的代码。
<div class="container">
<div class="row">
<?php
$select_stmt=$db->prepare("SELECT * FROM galeria ORDER BY id DESC;" ); //sql select query
$select_stmt->execute();
while($row=$select_stmt->fetch(PDO::FETCH_ASSOC))
{
?>
<div class="col-sm-2">
<div class="col-sm-12"><img src="upload/<?php echo $row['image']; ?>" class="imagem" style="height: 100px; weight: 100px;"></div>
<div class="col-sm-12"><a id=""><?php echo $row['texto'];?></a></div>
</div>
<?php
}
?>
</div>
</div>
答案 1 :(得分:0)
您只需要使用每个图像来构建项目。容器保持在循环之外。
<div class="container">
<?php
$select_stmt=$db->prepare("SELECT * FROM galeria ORDER BY id DESC;" ); //sql select query
$select_stmt->execute();
while($row=$select_stmt->fetch(PDO::FETCH_ASSOC))
{
?>
<div class="col-sm-2">
<div class="row">
<div class="col-sm-12"><img src="upload/<?php echo $row['image']; ?>" class="imagem" style="height: 100px; weight: 100px;"></div>
<div class="col-sm-12"><a id=""><?php echo $row['texto'];?></a></div>
</div>
</div>
<?php
}
?>
</div>
答案 2 :(得分:0)
您不应每行创建一个容器。只有一个包含所有行的容器
将您的代码更改为此:
<div class="container">
<?php
$select_stmt=$db->prepare("SELECT * FROM galeria ORDER BY id DESC;" ); //sql select query
$select_stmt->execute();
while($row=$select_stmt->fetch(PDO::FETCH_ASSOC))
{
?>
<div class="row">
<div class="col-sm-12">
<div class="col-sm-6"><img src="upload/<?php echo $row['image']; ?>" class="imagem" style="height: 100px; weight: 100px;"></div>
<div class="col-sm-6"><a id=""><?php echo $row['texto'];?></a></div>
</div>
</div>
<?php
}
?>
</div>
答案 3 :(得分:0)
我的方式
<div class="col-md-3 col-sm-6 col-xs-12">
<a href="/images/<?php echo...
</div>
或
<div style="float: left; margin-left: 20px; margin-top: 10px;">
<a href="/images/<?php echo...
</div>