Combining HTMTL with PHP code

Hi everyone,
With “escaped codes” ("heredoc ") I manged to display variables on my display whereby PHP and HTML combination.
using HTML file with PHP snippets I fail to show variable values.
here is the code:

<?php
require_once 'myInitial.php';
require_once 'myLogin.php';
MYSQLI_SET_CHARSET($myConnection,'UTF8');
?>
<!DOCTYPE html>
<!--forum_titles.html-->
<html>
  <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <head>
<body>
  <table>
    <tr>
      <th>counters</th>
    </tr>
    <?php
      $myQue = "SELECT  counter FROM hourshifts";
      $myResult = $myConnection->query($myQue);
      if (!$myResult) die ("Database access failed: " . $myConnection->error);
      $numOfRows = $myResult->num_rows;
      echo $numOfRows;
      for ($j = 0 ; $j < $numOfRows ; $j++)
      {
        $myResult->data_seek($j);
        $row = $myResult->fetch_array(MYSQLI_ASSOC);
      ?>
      <tr>
         <td><?php {$row["counter"]} ?></td> 
      </tr>
      <?php
         }
      ?>
   </table>
</body>
</html>

Variable " $numOfRows" is displayed correctly (203 rows) but “counter” column values becom null on my display as shown at the attached screenshot.

could anyone, please, explain why the values extracted from my SQL query are not displayed?
Thanks

// Change
<td><?php {$row["counter"]}?></td>
// To
<td><?php echo $row["counter"]; ?></td>

There are other approaches as well that might be a bit cleaner.

2 Likes

Thanks a lot !

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.