title: How to merge php and html code?
body: <p>I want to show a table. I am getting rows from database and according to that I want to show the data in table data.</p>
  
  <p>I want to show an image which will have source from database.</p>
  
  <p>As I am using ajax I am calling getPosts from ajax and showing it in a table, so I am returning the data from getPosts.php to show in a table.</p>
  
  <p>I have attempted to do it but getting stuck in syntax.  I want to add conditions while displaying data in table data.</p>
  
  <p>So It is giving an error.</p>
  
  <p>getPosts.php</p>
  
  <pre><code>    &lt;?php 
  
  ini_set('display_errors', 1);
  error_reporting(1);
  ini_set('error_reporting', E_ALL);
  
  include 'Database.php';
  
  $database = new Database(Constants::DBHOST,Constants::DBUSER,Constants::DBPASS,Constants::DBNAME);
  
  $dbConnection = $database-&gt;getDB();
  
  $stmt = $dbConnection-&gt;prepare("SELECT * FROM posts");
  $dbConnection-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  $stmt-&gt;execute();
  $results = $stmt-&gt;fetchall(PDO::FETCH_ASSOC);
  $posts='';
  
  if (count($results &gt; 0)) {
  
      $posts.='&lt;table&gt;&lt;tr&gt;&lt;th&gt;Title&lt;/th&gt;&lt;th&gt;Description&lt;/th&gt;&lt;th&gt;Url&lt;/th&gt;&lt;/tr&gt;';
  
      foreach($results as $row) {
  
          $posts .= '&lt;tr&gt;&lt;td&gt;' . $row['title'] . '&lt;/td&gt; &lt;td&gt;' . $row['description'] . '&lt;/td&gt;'  // getting error here 
  
                if (strcmp($row['url_type'],"2"))
                    {
                        '&lt;td&gt;&lt;a href="'.$row['ur'].'" target="_blank"&gt;
      &lt;image src="'.$row['thumb_url'].'" height="200" width="200"&gt;&lt;/image&gt;
      &lt;/a&gt;&lt;/td&gt;';
                    }
  
                    else{
  
          '&lt;td&gt;' . $row['url'] . '&lt;/td&gt;&lt;/tr&gt;';
  
      }
      }
  
  } else {
  
      $posts.='&lt;tr&gt;&lt;td&gt;No data found&lt;/td&gt;&lt;/tr&gt;';
  
  }
  
  $posts.='&lt;/table&gt;';
  
  echo $posts;
  
  ?&gt;
  </code></pre>
  
  <p>html:</p>
  
  <pre><code>    &lt;!doctype html&gt;
  &lt;html&gt;
  
  &lt;head&gt;
      &lt;style&gt;
          td {
              text-align: center;
              border: 1px solid black;
              border-collapse: collapse;
          }
      &lt;/style&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;title&gt;Posts&lt;/title&gt;
      &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
      &lt;script&gt;
  
  
          $(document).ready(function() {
  
  
              getValue();
  
          });
          function getValue() {
  
              $.ajax({
                  type: "POST",
                  url: 'getPosts.php',
                  dataType: 'text',
                  async: false,
                  cache: false,
                  success: function (result) {
  
                      // alert(result);
  
                      $('#table').html(result);
                  }
              });
          }
      &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;form method="post" enctype="multipart/form-data"&gt;
  
      &lt;table id="table" style="width:60%"&gt;
  
      &lt;/table&gt;
  
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Or Can I show these post in different format or design? I want to show the description,likes,views of post a thumbnail and url.</p>
  
  <p>Maybe like this:</p>
  
  <pre><code>&lt;div id="post"&gt;
  
  &lt;p&gt;Description&lt;/p&gt;
  &lt;a href="https://vimeo.com/channels/staffpicks/209597030" target="_blank"&gt;
  &lt;image src="http://i3.ytimg.com/vi/lQMdhS_oOvA/default.jpg" height="200" width="200"&gt;&lt;/image&gt;
  &lt;/a&gt;
  &lt;p&gt;likes&lt;/p&gt;&lt;p&gt;views&lt;/p&gt;
  &lt;p&gt;url&lt;/p&gt;
  </code></pre>
  
  <p></p>
  
  <p>I want to make it presentable.</p>