title: PHP How to show fetched results from the DB in console log
body: <p>I'm currently using the following code to fetch some data from my database table and show it into a table. It's using PDO for database connection.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;tbody&gt;
    &lt;?php $sql = "SELECT * from users 
          ORDER BY id DESC";
              $query = $dbh-&gt;prepare($sql);
              $query-&gt;execute();
              $results = $query-&gt;fetchAll(PDO::FETCH_OBJ);
              $cnt = 1;
              if ($query-&gt;rowCount() &gt; 0) {
                  foreach ($results as $result) {
  
              
                      ?&gt;
    &lt;form action="manage-users.php" method="post"&gt;
      &lt;input type="hidden" name="uid" value="&lt;?= $result-&gt;id ?&gt;" /&gt;
      &lt;?php
                          $status = 1;
                          if ($result-&gt;status == 1) {
                              $status = 0;
                          }
                          ?&gt;
        &lt;input type="hidden" name="status" value="&lt;?= $status ?&gt;" /&gt;
        &lt;tr&gt;
  
          &lt;td&gt;
            &lt;?php echo htmlspecialchars($cnt); ?&gt;
          &lt;/td&gt;
          &lt;td&gt;
            &lt;?php echo htmlspecialchars($result-&gt;full_name); ?&gt;
          &lt;/td&gt;
          
  
        &lt;/tr&gt;
    &lt;/form&gt;
    &lt;?php $cnt = $cnt + 1;
  
  
                  }
              } ?&gt;
  &lt;/tbody&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>But I wanted to console log the fetched results, so I modified my code as below.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;tbody&gt;
    &lt;?php $sql = "SELECT * from users 
          ORDER BY id DESC";
              $query = $dbh-&gt;prepare($sql);
              $query-&gt;execute();
              $results = $query-&gt;fetchAll(PDO::FETCH_OBJ);
              $cnt = 1;
              if ($query-&gt;rowCount() &gt; 0) {
                  foreach ($results as $result) {
  
                      echo '&lt;script type="text/javascript"&gt;' .
                          'console.log(' . $results . ');&lt;/script&gt;';
  
                      ?&gt;
    &lt;form action="manage-users.php" method="post"&gt;
      &lt;input type="hidden" name="uid" value="&lt;?= $result-&gt;id ?&gt;" /&gt;
      &lt;?php
                          $status = 1;
                          if ($result-&gt;status == 1) {
                              $status = 0;
                          }
                          ?&gt;
        &lt;input type="hidden" name="status" value="&lt;?= $status ?&gt;" /&gt;
        &lt;tr&gt;
  
          &lt;td&gt;
            &lt;?php echo htmlspecialchars($cnt); ?&gt;
          &lt;/td&gt;
          &lt;td&gt;
            &lt;?php echo htmlspecialchars($result-&gt;full_name); ?&gt;
          &lt;/td&gt;
  
  
        &lt;/tr&gt;
    &lt;/form&gt;
    &lt;?php $cnt = $cnt + 1;
  
  
                  }
              } ?&gt;
  &lt;/tbody&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>But the issue is it's not showing any data or error in the console. Any help would be much appreciated.</p>