首页 > 解决方案 > 当我在论坛中发布来自 mysql 数据库的数据时,它们不会堆叠

问题描述

我的论坛有问题,当我尝试在我的论坛上发布用户帖子时,帖子继续在同一行上,而不是像它应该的那样堆叠(段落)。此外,当我的数据库中有大量数据时,它只会让我的整个网站更宽,而不是堆叠文本。

目前我正在使用 php 并将我的数据存储在 mysql 数据库中,数据正确来自数据库。但同样是我的数据库中的数据如何显示的问题。

Html/php code:

<?php
require "header.php";
include 'includes/dbh.inc.php';
?>
<body>
 <div class="container">
  <form action="aalesund.php" method="POST">
  <div class="row">
    <div class="col-25">
      <label for="subject">Subject</label>
    </div>
    <div class="col-75">
      <input type="text" name="subject" placeholder="Subject">
    </div>
  </div>
  <div class="row">
    <div class="col-25">
      <label for="content">Content</label>
    </div>
    <div class="col-75">
      <textarea type="text" name="content" placeholder="Write something..." 
style="height: 200px"></textarea>
    </div>
  </div>
  <div class="row">
    <div class="col-25">
      <label for="date">Date and time</label>
    </div>
    <div class="col-75">
      <input type="text" name="date" placeholder="Please write the date and 
time">
    </div>
    <div class="button-container">
      <button class="postButton" type="submit" name="submit">Write 
post</button>
    </div>
    </form>

<?php
  $subject = $_POST['subject'];
  $content = $_POST['content'];
  $date = $_POST['date'];

  $sql = "INSERT INTO posts (subject, content, date) VALUES ('$subject', 
'$content', '$date');";
  $result = mysqli_query($conn, $sql);

  header("Location ../aalesund.php?post=succsesfull");

  $sql = "SELECT * FROM posts ORDER BY id DESC;";
  $result = mysqli_query($conn, $sql);
  $resultCheck = mysqli_num_rows($result);

  if ($resultCheck > 0) {
    while ($row = mysqli_fetch_assoc($result)) {
      ?>
        <article class="forum">
          <h1 style="font-size: 20px"><?php echo $row['subject']; ?></h1>
          <p class="forumContent"><?php echo $row['content']; ?></p>
          <p class="forumDate"><?php echo $row['date']; ?></p>
        </article>
 <?php
    }
  }
 ?>

<?php
  require "footer.php";
 ?>

Part of the css code:

 .forumContent {
  text-align: center;
}

.forumDate {
  text-align: right;
  color: #ff9933;
}

.forum {
  background-color: #FFFFFF;
  margin: 5px;
  padding-left: 20px;
  padding-right: 20px;
}

(对不起意大利面条代码)

标签: phphtmlmysql

解决方案


推荐阅读