doudu8291 2014-11-25 12:25
浏览 73
已采纳

htmlspecialchars_decode导致宽度问题

I have been messing about creating stuff in PHP so decided to create a site... However, when I am pulling things from my DB it is resizing the text and pushing things off of the page :/

I have tested with plain text and my site is displaying correctly: http://gentetcreations.co.uk/blog-2.php

However, with HTML text it displays in a weird way and I can't seem to get it fixed: http://gentetcreations.co.uk/blog-1.php

JSFidle here!

<!DOCTYPE HTML>
<html>
<head>
  <title>GentetCreations</title>
  <meta charset="UTF-8">
  <link rel="stylesheet" type="text/css" href="style/style.css" />
</head>
<body>

  <div id="main">
    <?php
    include("inc/pageHead.php");
    ?>
    <div id="site_content">
      <?php
      include("inc/side.php");
      ?>
      <div id="content">
        <?php
        include("inc/dbconnection.php");
        $id = $_GET['id'];
        $id = trim($id);
        $result = mysqli_query($conn, "SELECT * FROM  blog WHERE authorised = 1 AND blog_id = '" . $id . "'"); 
        if(!$result) {
          die("Database query failed: " . mysqli_error($conn));
        } else {
          $rows = mysqli_num_rows($result);
          if ($rows > 0) {
            while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
              $tags = "";
              $result2 = mysqli_query($conn, "SELECT * FROM tags WHERE blog_id = '" . $row['blog_id'] . "'");
              if(!$result2) {
                die("A Database query failed: " . mysqli_error($conn));
              } else {
                while ($row2 = mysqli_fetch_array($result2, MYSQLI_ASSOC)) {
                  $rawTag  = $row2['tag'];
                  $tag = str_replace(" ", "", $rawTag);
                  $tags .= "<a href='tag-" . $tag . ".php'>" . $tag . "</a> ";
                }
              }
              echo "
              <span class='mainContentWidth'>
                <table>
                  <tr>
                    <th>
                      <a href='blog-" . $row['blog_id'] . ".php'>
                        <h2>" . $row['title'] . "</h2>
                      </a>
                    </th>
                  </tr>
                  <tr>
                    <td>
                      <p>" . date("d/m/Y", strtotime($row['createdDate'])) . "</p><br />
                      <span>" . $row['content'] . "</span>
                      <br />
                      <br />
                      <span><small>Tags: " . $tags . "</small></span>
                    </td>
                  </tr>
                </table>
              </span>";
      } //$row = mysqli_fetch_array($result, MYSQLi_ASSOC)
  } else { //$rows > 0
    echo "<br /><h1>An error occurred.</h1><br /><h2>The blog you were looking for could not be found.</h2>";
  }
}
?>
</div>
</div>
<?php
include("inc/footer.php");
?>
</div>
</body>
</html>

I am new to doing web based coding so I am really confused here and not too sure what is going on.

If anyone could help me here or push me in the right direction to display everything correctly, I would be very happy!

  • 写回答

1条回答 默认 最新

  • duankousong9637 2014-11-25 12:40
    关注

    You have block level elements inside a span tag. You should avoid doing that.

    For current issue you can add this CSS

    table tr td > span {
      width: 615px;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法