Horizontal Navbar Pulling Database Tables in PHP

I’m new to learning PHP. I’m trying to build a database-driven website in which I’d like to pull tables & display the items within these tables.

Now, I know that it seems most developers are designing their horizontal navigation bars by pulling data from their db tables to dynamically generate these navbars, but I was also wondering if it’s possible to do it vice versa or if it’s even something that should be considered. In other words, I already have my navbar built in CSS & HTML (populated by html ul & li structure) but I would like for the user to be able to click on the navbar & based off of the link clicked in the navbar, that will be the table that’s pulled from the database & then displayed onto the main index.php page. Is this even a practical way? It seems to be backwards from some tutorials that I’ve seen around.

would make no sense if you have a menu and do not know what was clicked afterwards… so yes, if your menu provides some kind of identifier (like a flag in the URL index.php?page=contact) you can grap that via $_GET


then you build your conditional SQL select foo from bar where name = ? and execute this via PDO with the corresponding $_GET variable.

i would recommend to use a whitelist, or predefined SQL statements for different SQL tables, for the tables the user is able to select.

1 Like

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