0

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!

Tim
  • 489
  • 4
  • 17
  • Your code is vulnerable to [SQL injection](http://stackoverflow.com/q/601300/2257664). The SQL code seems irrelevant here since it's only a layout problem. Please post a [SSCCE](http://meta.stackexchange.com/q/22754/237701) question, for example by putting the HTML and CSS code on JSFiddle. – A.L Nov 25 '14 at 12:28
  • `` is supposed for inline text/markup; use `
    ` for block-level contents.
    – Gumbo Nov 25 '14 at 12:44

1 Answers1

1

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;
}
anpsmn
  • 7,062
  • 2
  • 25
  • 43