Using an html link to display text from database

I have the following code:

<table id="topMenu">
           <tr>
               <td>
                   <h1 class="siteName">Scarab Beetle</h1>
               </td>
               
                <?php

                $stmt = $pdo->query("SELECT * FROM testtable01");

                while ($row = $stmt->fetch()) {
                   echo "<td class='navItem'>" . "<a href='#'>" . $row['testmenu1'] . "</a>" . "</td>"; 
                }

                ?>
                   
           </tr>
       </table>
       
       <!-- body text -->
       
       <?php 
                   echo "<p>" . $row['testsubmenu1'] . "</p>";
       ?>

What I am trying to do is when the ‘home’ page link is click, the data relating to home, is shown on index, and so on for the other menu items.

At the moment, I get an error message: Trying to access array offset on value of type bool .

I would like help on getting the text for home page displayed.

Thanks in advance.

Hello!

Try printing the entire rows instead, so you can see what each $stmt->fetch() is retrieving:

while ($row = $stmt->fetch()) {
  print_r($row);
}
1 Like

Thank you for the help. I am still working on a solution, but your code may help with other parts of my site.

1 Like

Something that may help you further is a debugger, know what it is? If not, try to setup xDebug in your machine, along with your IDE (or code editor) and browser plugin.

Depending on how you’re working on your project, your setup may already have installed xdebug, so you would need to configure the IDE/code editor and browser.

1 Like

Thanks, this will help.

1 Like