在单独的DIV中显示MySQL的每一行 [英] Display each row from MySQL in a separate DIV

查看:54
本文介绍了在单独的DIV中显示MySQL的每一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个职位表,其中包含职位字段.假设我要在10个div中显示10个帖子.我应该如何进行呢?我设法使用while循环获取了全部内容,但是那只显示了一个地方的全部内容,而且我想为每个帖子设置单独的div(以便我可以使用不同的背景色).

I have a posts table which contains a field for the posts. Let's say I have 10 posts that i want to show in 10 divs. How should I proceed in doing that? I've managed to get the full contents using a while loop, but that only shows the full contents in one place, and I want to have individual divs (so i can use different background colors) for each individual post.

请帮帮我,我希望这是有道理的.试想一下例如Facebook显示帖子的方式.每个帖子都有自己的盒子.我想要类似的东西.

Help me out please, I hope it makes sense. Just think at the way facebook displays posts for example. Each post has it's own box. I want something similar.

我必须获取帖子的代码片段可在此处找到:

Snippet of the code I have to get the posts is available here:

<?php
require_once("includes/database.php"); // Get the database connection

$get_post = "SELECT full_post FROM posts";
$show_post = mysqli_query($connection, $get_post);

if (!$show_post) {
echo "Could not load post. " . "(" . mysqli_error($connection) . ")";
}
while ($post = mysqli_fetch_assoc($show_post)) {
echo $post["full_post"] . "<br />";
}
mysqli_free_result($show_post);

?>

推荐答案

最简单的方法是使用while函数创建div,该div显示您的帖子并向其中添加CSS类.

The easiest method of doing this is creating the divs from the while function that's showing your posts and adding CSS classes to them.

示例:

while ($post = mysqli_fetch_assoc($show_post)) {
echo '<div class="blue">';
echo $post["full_post"] . "<br />";
echo '</div>';
}

这篇关于在单独的DIV中显示MySQL的每一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆