Show related page menus

Let’s say there is a dynamic menu that is displayed through a query from the database. How to generate element selection? Those. we clicked on any element and so that the page is displayed accordingly to the selected one? We have one template for all pages. And so that this template (a certain section of it) is filled with content? As I understand it, when we click on a menu item, we execute a query to the database, where the page id refers to the menu id. Here is how to do it? Does anyone have sample code snippets? And then I pick something and nothing happens.

Menu – JS + CSS.

Answer 1, authority 100%

The question is certainly powerful, right on the development of an entire CMS 🙂
But let’s try to draw something.
We have one template for everything-pro-everything, a ready-made generated menu and a table in the database in which our pages are located.
We also have an index.php page (template), in which everything will happen, well,
let the menu look like this:

    <li><a href="?id=1"> 1</a></li>
    <li><a href="?id=2"> 2</a></li>
    <li><a href="?id=3"> 3</a></li>

Here is the actual code for this page (index.php):

//   -,      index.php  ?id=
$pageTitle  = "  ";
$pageContent    = "  ";
// ,          id    
if ( isset($_GET['id']) && !empty($_GET['id']) ) {
// ,    /index.php?id=2
//          , id  = 2
$sql = "SELECT title, content FROM pages WHERE id = '".$_GET['id']."'";
$res = mysql_query($sql);
while($r=mysql_fetch_array($res)) {
$pageTitle = $r["title"]; //    
$pageContent = $r["content"]; //    
<table border="0" cellpadding="0" cellspacing="0" width="800">
        <td width="300">

<br />
    <li><a href="?id=1"> 1</a></li>
    <li><a href="?id=2"> 2</a></li>
    <li><a href="?id=3"> 3</a></li>
        <td width="500">

<br />

Now there are coders who will say that it is not correct to use mysql_query now, but for the simplest CMS it will be more than enough for this example 🙂

By the way, you can see an example of this simple sms here.