Using page id to load text into html page

What I have is a menu with links. What I want to happen is when clicked, information for that page is displayed on the index page. So, for example, clicking About.php, will add about page text from a database to a tag in the page.

I have this menu (code):

<?php

               $stmt = $pdo->query("SELECT * FROM testtable01");
          
                while ($row = $stmt->fetch()) { 
                    echo "<td class='navItem'>" . "<a href='index.php'>" . $row['testmenu1']. "</a>" . "</td>"; 
                }
                
                ?>

In the same page, I have the place where I want the text to appear:

<?php echo $row['testsubmenu1']; ?>

I understand that this gives an error message " Trying to access array offset on value of type bool in C:\xampp\htdocs\Testpage\index.php", but this may be part of what I am not doing, so any help in getting text from database using page id to a tag will be appreciated.

Would you mind sharing your github link. It would easier to help you that way.

Hello Noah,

This my GitHub link as requested: GitHub - steve-by/Testing123: Tests

Regards

Stephen

So what is happening is that it’s exiting the while loop by turning $row into null. I think you know that. This is what is causing the error and why you can’t echo out the information.

I submitted a pull request to your repository with some suggestions and a working demo.

PR

Suggested Code

Let me know if that helps and what you think.

Keep up the good work!!!

Noah

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