4
I read in several places that you should not mix PHP with HTML and vice versa, How then could I separate this code for example:
<?php include 'C:\xampp\htdocs\trabweb\sessaoBD.php' ?> <!--entra na sessão e na database -->
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
  <title>Trabalho web</title>
  <meta charset="utf-8">
  <link rel="stylesheet" type="text/css" href="http://localhost/trabweb/css/style_hashbase.css"> <!--css do site N-O-D-E, apenas algumas modificações feitas -->
  <script src="js/jquery-3.2.1.min.js"></script>
  <script src="js/bootstrap.js"></script>
</head>
<body>
<?php include 'C:\xampp\htdocs\trabweb\header.html' ?> <!--cabeçalho da pagina-->
  <div id="content">
    <div id="page">
        <div id="list">
<div id="post">
  <?php if ($login === true and $_SESSION["user_name"] === "lucas"): ?> <!--checa se é o ADMIN, caso sim ele podera fazer um novo post -->
    <a href="http://localhost/trabweb/crianewpost.php">*NEW POST*</br></br></a> <!--redirige a pagina de criar um novo post  -->
    <?php endif; ?>
<!--mostra todos posts na tela -->
          <?php
          $sql =  "select titulo,id from POSTS";
          //$sql = "DELETE FROM POSTS" ;
          $result = $conn->query($sql);
          if ($conn->query($sql) === false) {
              echo "Error: " . $sql . "<br>" . $conn->error;
          }
          if ($result->num_rows > 0) {
              // output data of each row
              while ($row = $result->fetch_assoc()) {
                  echo  '<a method="get" href= "http://localhost/trabweb/db/seleposts.php?posts_id='.$row['id'].'">'.$row["titulo"].'</a> <br>'; //cada post é um link para o seu conteudo
              }
          } else {
              echo "0 results";
          }
          ?>
</div>
        </div>
      </div>
    </div>
  </body>
  </html>
If you want to build HTML with PHP, you essentially have to mingle the two. What you can do there is to separate things: PHP that defines PHP layout that defines logic, such as SQL execution.
– Woss
Lucas the best way to separate php from html is by using some template framework. Currently Twig (template engine) or Blade meets this need a lot. If you are using php without framework Twig may fall very well...
– user3537289
studies about MVC a good would be using a framework called Phalcon the structure of it already allows creating layouts and its performance is the best
– Jasar Orion
I would recommend staying well away from frameworks per hour. If you don’t master the basics, it makes no sense to want to master the advanced. As I always say, frameworks are solutions to specific problems. Using them for a different purpose is a mistake that brings more harm than good.
– Woss