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;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!