If I'm understanding things correctly (not a given), it sounds like you'd want a separate query to fetch the content based on the pageheader
value in the HTTP request. (You could then reduce what gets returned by the menu link query by only specifying that that pageheader
column be returned.)
Also, I'd suggest making your menu links include a "key" in the query string, so that you can grab what you need from $_GET
explicitly. I'd also make the values "html safe".
<a href='index.php?page=<?php echo urlencode($row["pageheader"]); ?>'><?php echo htmlentities($row["pageheader"]); ?></a>
In fact, after looking at that, what I'd actually do is... 😉
printf(
"<a href='index.php?page=%s'>%s</a>",
urlencode($row["pageheader"]),
htmlentities($row["pageheader"])
);
Anyway...then to display the selected page's content, you might do something like:
$page = empty($_GET['page']) ? 'Home' : $_GET['page'];
$content_stmt = $dbh->prepare("SELECT * FROM pages where pageheader = :page");
$content_stmt->execute([':page' => $_GET['page']);
// if nothing returned, maybe display a 404 Not Found page?
// else display content retrieved by the query