我知道这个问题以前已经提出了很多,但我仍然不能让它起作用。我正在尝试添加我制作的每个帖子,以并排显示每个3-4列。现在,我有这样的东西:

但我想让它们并排在一起,就像这样

(图片来自上一个问题)。下面是我的代码片段
<div>
<?php
global $connection;
$nRows = $connection->query("SELECT *
FROM posts
ORDER BY post_id DESC");
if($nRows->rowCount() > 0) {
while ($row = $nRows->fetch()) {
$post_title = str_replace('_', ' ', $row['post_title']);
$post_author = $ed->encrypt_decrypt('decrypt',$row['post_author']);
$post_file = $row['post_file'];
$post_date = $row['post_time'];
?>
<!-- Blog Content BEGIN Display-->
<div class="column">
<h2>
<!-- This redirects you to a specific post -->
<a href="post/postFetch/fetchByTitle/fetchByPT.php?post_id=<?php echo $row['post_id'];?>&post_title=<?php echo $row['post_title'];?>" class="link-post-title" style="font-family: Arial"><?php echo "#".$row['post_id'] . " ". $post_title;?></a>
</h2>
<p class="lead" style="font-family: FontAwesome">
<!-- This redirects you to the post author -->
 <a href="post/postFetch/fetchByAuthor/fetchByPA.php?post_author=<?php echo $row['post_author'];?>" class="link-post-author" style="font-family: Arial"><?php echo $post_author;?> </a> <?php //echo ' ' . '#' . str_replace(',', '#', $row['post_tags']);?>
</p>
<!-- if there is no image, just remove the entire div --><?php
$file_parts = pathinfo($post_file);
if(isset($file_parts['extension'])){
switch ($file_parts['extension']){
case "jpg":
if(!empty($post_file)) { ?>
<div class="imgBox">
<img src="post/postFiles/<?php echo $post_file;?>">
</div><?php
}
break;
case "mp4":?>
<div class="vidBox">
<video width="615" height="315" controls>
<source src="post/postFiles/<?php echo $post_file;?>">
</video>
</div><?php
break;
case "": // Handle file extension for files ending in '.'
case NULL: // Handle no file extension
break;
}
}?>
<p style="font-family: Arial"><span class="glyphicon glyphicon-time"></span><?php
echo "Posted on " . $post_date;?>
</p>
</div>
<!-- Blog Content END Display --><?php
}
} else { ?>
<p style="color: darkgoldenrod" class="mssgAlign"><u>NO RECORDS</u></p><?php
}
$nRows = null;
}?>
</div>我没有使用Bootstrap。也许这是我的错误,我应该开始这样做,但在此期间,我将继续我的做法。欢迎任何帮助/提示
发布于 2021-02-11 19:40:59
您可以将每4列(带有内容的div)的组包装在包装器(parent Div)中,并设置样式列以显示内嵌块。
<?php
$break = 0;
for($i = 0; $i < 200; $i++)
{
if($break % 4 === 0)
{
echo '<br>open div<br/>'; //your wrapper/row start
}
$break++;
echo $i . ' '; //your column with content
if($break % 4 === 0)
{
echo '<br />close div<br />'; //your wrapper/row end
}
}https://stackoverflow.com/questions/66148683
复制相似问题